mirror of
https://github.com/apache/nuttx.git
synced 2025-12-06 09:01:15 +08:00
arch/avr/src/avrdx: add support for TWI (I2C and SMBus) peripheral
This patch adds support for Two-Wire interface in AVR Dx chips. Only master mode is supported in this version. The driver was tested using TC74Ax thermal sensor and simple application that read the temperature from it. (Driver for the sensor is not in-tree.) Signed-off-by: Kerogit <kr.git@kerogit.eu>
This commit is contained in:
109
Documentation/platforms/avr/avrdx/docs/twi.rst
Normal file
109
Documentation/platforms/avr/avrdx/docs/twi.rst
Normal file
@@ -0,0 +1,109 @@
|
||||
===============================
|
||||
Two Wire Interface in AVR DA/DB
|
||||
===============================
|
||||
|
||||
Two Wire Interface is AVR peripheral capable of supporting both I\ :sup:`2`\ C and SMBus.
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
|
||||
Pointer to initialized ``struct i2c_master_s`` can be obtained using
|
||||
|
||||
.. code-block:: c
|
||||
|
||||
FAR struct i2c_master_s *i2c;
|
||||
i2c = avrdx_initialize_twi(0);
|
||||
|
||||
|
||||
This function will initialize the peripheral based on configuration specified
|
||||
via Kconfig. It may be called multiple times, only first call will perform
|
||||
the initialization - subsequent calls will only return the pointer.
|
||||
|
||||
Deinitialization is currently not supported.
|
||||
|
||||
The parameter denotes which peripheral is to be initialized. With current chips,
|
||||
permitted values are ``0`` and ``1``.
|
||||
It is ignored if the chip has only single TWI interface.
|
||||
|
||||
Configuration options
|
||||
=====================
|
||||
|
||||
Pin selection
|
||||
-------------
|
||||
|
||||
This option makes it possible to choose which I/O pins will be connected
|
||||
to the peripheral.
|
||||
|
||||
Mode selection
|
||||
--------------
|
||||
|
||||
The peripheral supports Standard, Fast and Fast Plus modes.
|
||||
|
||||
Quick commands
|
||||
--------------
|
||||
|
||||
SMBus permits transactions that contain no data. Instead, the R/nW bit
|
||||
is interpreted as a single-bit datum by the target device. If this is enabled,
|
||||
I\ :sup:`2`\ C messages with zero length are interpreted as quick commands. If not,
|
||||
zero-length messages are not permitted and the transmission is rejected
|
||||
with ``EINVAL``
|
||||
|
||||
Forbid NOSTART
|
||||
--------------
|
||||
|
||||
NuttX upper half of the I\ :sup:`2`\ C driver permits ``I2C_M_NOSTART``
|
||||
flag for a message, indicating that the message is not a standalone entity
|
||||
but rather a continuation of previous message. Since not all drivers need
|
||||
this and program memory space is not unlimited on the chip, this configuration
|
||||
option can be used to remove support for such messages.
|
||||
|
||||
Transmission that submits message with this flag will be rejected
|
||||
with ``EINVAL`` if this configuration option is set. Enable this only
|
||||
if you know internals of I\ :sup:`2`\ C drivers used by your application.
|
||||
|
||||
Limitations
|
||||
===========
|
||||
|
||||
Mode and addressing
|
||||
-------------------
|
||||
|
||||
Currently, only master mode is supported.
|
||||
|
||||
Only 7-bit addressing is supported. The peripheral does not support 10-bit
|
||||
addressing directly and the driver software does currently have no support
|
||||
for that either. I\ :sup:`2`\ C messages requesting 10-bit address
|
||||
are rejected with ``ENOTSUP``.
|
||||
|
||||
Message limitations
|
||||
-------------------
|
||||
|
||||
Maximum message count for single transmission is 127.
|
||||
|
||||
The driver does not support ``I2C_M_NOSTOP`` flag for last submitted message.
|
||||
As per rules specified in ``include/nuttx/i2c/i2c_master.h``, the I\ :sup:`2`\ C
|
||||
driver lower half is supposed to leave the bus occupied if the last
|
||||
of the submitted messages has this ``NOSTOP`` flag set. This driver
|
||||
is not capable of doing that.
|
||||
|
||||
Also not supported is ``I2C_M_NOSTART`` flag for first submitted message.
|
||||
First message within the transfer always starts with ``START`` condition.
|
||||
|
||||
Messages with zero length (which are only permitted based on configuration
|
||||
- see above) may not specify ``I2C_M_NOSTART`` nor ``I2C_M_NOSTOP``.
|
||||
(Such a message is interpreted as a quick command and quick commands
|
||||
must end with a ``STOP`` condition according to the chip's documentation.)
|
||||
|
||||
Inactivity timeout
|
||||
------------------
|
||||
|
||||
The driver configures timeout for bus inactivity during initialization.
|
||||
This timeout is used by the hardware to switch its internal state
|
||||
from "bus is busy" or "bus is in unknown state" to "bus is idle."
|
||||
This transition otherwise only happens after a ``STOP`` condition is detected
|
||||
or when forced by software.
|
||||
|
||||
This timeout remains in effect during normal TWI operation as well.
|
||||
Such a timeout is defined for SMBus but not for I\ :sup:`2`\ C; nevertheless,
|
||||
the driver does not distinguish between the two and the timeout is always
|
||||
in place.
|
||||
@@ -51,12 +51,13 @@ Peripheral Support
|
||||
|
||||
The following list indicates peripherals supported in NuttX:
|
||||
|
||||
========== ================
|
||||
========== =======================
|
||||
Peripheral Notes
|
||||
========== ================
|
||||
========== =======================
|
||||
GPIO In board code
|
||||
UART See below
|
||||
========== ================
|
||||
TWI Master only, more below
|
||||
========== =======================
|
||||
|
||||
GPIO
|
||||
----
|
||||
@@ -101,6 +102,12 @@ This for example means that ``USART1`` peripheral will always
|
||||
be accessed through ``/dev/ttyS1`` regardless of what other ``USART``
|
||||
peripherals are enabled (if any.)
|
||||
|
||||
TWI
|
||||
---
|
||||
|
||||
Currently, only master is supported. Implementation details and quick
|
||||
usage instructions can be found in :doc:`docs/twi` document.
|
||||
|
||||
Supported Boards
|
||||
================
|
||||
|
||||
|
||||
@@ -71,6 +71,23 @@ config AVR_HAS_PORTG
|
||||
bool
|
||||
default n
|
||||
|
||||
# Available TWI interfaces and their options (not common for all devices)
|
||||
config AVR_HAVE_TWI0_ALT1
|
||||
bool
|
||||
default n
|
||||
---help---
|
||||
Chip has alternate pin configuration 1 for TWI0
|
||||
|
||||
config AVR_HAVE_TWI1
|
||||
bool
|
||||
default n
|
||||
|
||||
config AVR_HAVE_TWI1_ALT1
|
||||
bool
|
||||
default n
|
||||
---help---
|
||||
Chip has alternate pin configuration 1 for TW1
|
||||
|
||||
choice
|
||||
prompt "Atmel AVR DA/DB chip selection"
|
||||
default ARCH_CHIP_AVR128DA28
|
||||
@@ -96,6 +113,9 @@ config ARCH_CHIP_AVR128DA64
|
||||
select AVR_HAS_PORTB
|
||||
select AVR_HAS_PORTE
|
||||
select AVR_HAS_PORTG
|
||||
select AVR_HAVE_TWI0_ALT1
|
||||
select AVR_HAVE_TWI1
|
||||
select AVR_HAVE_TWI1_ALT1
|
||||
---help---
|
||||
Atmel AVR128DA64 8-bit AVR.
|
||||
|
||||
@@ -113,6 +133,9 @@ config ARCH_CHIP_AVR128DB64
|
||||
select AVR_HAS_PORTB
|
||||
select AVR_HAS_PORTE
|
||||
select AVR_HAS_PORTG
|
||||
select AVR_HAVE_TWI0_ALT1
|
||||
select AVR_HAVE_TWI1
|
||||
select AVR_HAVE_TWI1_ALT1
|
||||
---help---
|
||||
Atmel AVR128DB64 8-bit AVR.
|
||||
|
||||
@@ -328,6 +351,173 @@ config AVR_USART5_NONE
|
||||
|
||||
endchoice
|
||||
|
||||
config AVR_TWI0
|
||||
bool "Enable TWI (I2C) driver for interface 0"
|
||||
depends on I2C
|
||||
---help---
|
||||
Enable driver for TWI0
|
||||
|
||||
choice AVR_TWI0_ALT
|
||||
prompt "TWI0 pin selection"
|
||||
depends on AVR_TWI0
|
||||
default AVR_TWI0_ALT0
|
||||
---help---
|
||||
Select which I/O pins will be driven by TWI0 interface.
|
||||
Refer to I/O Multiplexing and Port Multiplexer sections
|
||||
in chip documentation for specifics.
|
||||
|
||||
config AVR_TWI0_ALT0
|
||||
bool "Default TWI0 pinout"
|
||||
|
||||
config AVR_TWI0_ALT1
|
||||
bool "Alternate TWI0 pinout 1"
|
||||
depends on AVR_HAVE_TWI0_ALT1
|
||||
|
||||
config AVR_TWI0_ALT2
|
||||
bool "Alternate TWI0 pinout 2"
|
||||
|
||||
endchoice
|
||||
|
||||
choice AVR_TWI0_MODE
|
||||
prompt "TWI0 mode selection"
|
||||
depends on AVR_TWI0
|
||||
default AVR_TWI0_MODE_STD
|
||||
---help---
|
||||
Select TWI0 operating mode.
|
||||
|
||||
config AVR_TWI0_MODE_STD
|
||||
bool "Standard mode"
|
||||
|
||||
config AVR_TWI0_MODE_FAST
|
||||
bool "Fast mode"
|
||||
|
||||
config AVR_TWI0_MODE_FASTPLUS
|
||||
bool "Fast plus mode"
|
||||
|
||||
endchoice
|
||||
|
||||
choice AVR_TWI0_SDAHOLD
|
||||
prompt "SDA hold time selection"
|
||||
depends on AVR_TWI0
|
||||
default AVR_TWI0_SDAHOLD_OFF
|
||||
---help---
|
||||
Select TWI0 SDA hold time. Refer to Electrical Characteristics
|
||||
in chip documentation for details
|
||||
|
||||
config AVR_TWI0_SDAHOLD_OFF
|
||||
bool "Hold time OFF"
|
||||
|
||||
config AVR_TWI0_SDAHOLD_50NS
|
||||
bool "50ns (short)"
|
||||
|
||||
config AVR_TWI0_SDAHOLD_300NS
|
||||
bool "300ns (meets SMBus 2.0 specs under typical conditions)"
|
||||
|
||||
config AVR_TWI0_SDAHOLD_500NS
|
||||
bool "500ns (meets SMBus 2.0 specs across all corners)"
|
||||
|
||||
endchoice
|
||||
|
||||
config AVR_TWI1
|
||||
bool "Enable TWI (I2C) driver for interface 1"
|
||||
depends on I2C
|
||||
depends on AVR_HAVE_TWI1
|
||||
---help---
|
||||
Enable driver for TWI0
|
||||
|
||||
choice AVR_TWI1_ALT
|
||||
prompt "TWI0 pin selection"
|
||||
depends on AVR_TWI1
|
||||
default AVR_TWI1_ALT0
|
||||
---help---
|
||||
Select which I/O pins will be driven by TWI1 interface.
|
||||
Refer to I/O Multiplexing and Port Multiplexer sections
|
||||
in chip documentation for specifics.
|
||||
|
||||
config AVR_TWI1_ALT0
|
||||
bool "Default TWI1 pinout"
|
||||
|
||||
config AVR_TWI1_ALT1
|
||||
bool "Alternate TWI1 pinout 1"
|
||||
depends on AVR_HAVE_TWI1_ALT1
|
||||
|
||||
config AVR_TWI1_ALT2
|
||||
bool "Alternate TWI1 pinout 2"
|
||||
|
||||
endchoice
|
||||
|
||||
choice AVR_TWI1_MODE
|
||||
prompt "TWI1 mode selection"
|
||||
depends on AVR_TWI1
|
||||
default AVR_TWI1_MODE_STD
|
||||
---help---
|
||||
Select TWI1 operating mode.
|
||||
|
||||
config AVR_TWI1_MODE_STD
|
||||
bool "Standard mode"
|
||||
|
||||
config AVR_TWI1_MODE_FAST
|
||||
bool "Fast mode"
|
||||
|
||||
config AVR_TWI1_MODE_FASTPLUS
|
||||
bool "Fast plus mode"
|
||||
|
||||
endchoice
|
||||
|
||||
choice AVR_TWI1_SDAHOLD
|
||||
prompt "SDA hold time selection"
|
||||
depends on AVR_TWI1
|
||||
default AVR_TWI1_SDAHOLD_OFF
|
||||
---help---
|
||||
Select TWI1 SDA hold time. Refer to Electrical Characteristics
|
||||
in chip documentation for details.
|
||||
|
||||
config AVR_TWI1_SDAHOLD_OFF
|
||||
bool "Hold time OFF"
|
||||
|
||||
config AVR_TWI1_SDAHOLD_50NS
|
||||
bool "50ns (short)"
|
||||
|
||||
config AVR_TWI1_SDAHOLD_300NS
|
||||
bool "300ns (meets SMBus 2.0 specs under typical conditions)"
|
||||
|
||||
config AVR_TWI1_SDAHOLD_500NS
|
||||
bool "500ns (meets SMBus 2.0 specs across all corners)"
|
||||
|
||||
endchoice
|
||||
|
||||
if AVR_TWI0 || AVR_TWI1
|
||||
|
||||
config AVR_TWI_QCEN
|
||||
bool "Quick command enabled"
|
||||
default false
|
||||
---help---
|
||||
Enable Quick Command mode. In this mode, messages with
|
||||
zero-length data are interpreted as SMBus quick commands
|
||||
which use R/non-W bit as a single bit of data transmitted
|
||||
(written) to the target device.
|
||||
|
||||
If not enabled, attempt to transmit message with zero-length
|
||||
is an error rejected with EINVAL.
|
||||
|
||||
config AVR_TWI_FORBID_NOSTART
|
||||
bool "Forbid I2C NOSTART to save flash space"
|
||||
default false
|
||||
---help---
|
||||
NuttX I2C message can be submitted with a flag that indicates
|
||||
that the caller does want that message processed without
|
||||
issuing start condition on the BUS (presumably with previous
|
||||
message set to not issue STOP nor REPEATED START condition.)
|
||||
|
||||
Since not many drivers require this, it is possible to exclude
|
||||
support for this flag from the build. Any I2C device driver
|
||||
that attempt to submit such message will receive EINVAL.
|
||||
|
||||
If you know that your system's drivers do not use I2C_M_NOSTART,
|
||||
you can enable this option to save around 120 bytes of flash space.
|
||||
|
||||
endif
|
||||
|
||||
endmenu # AVR DA/DB Peripheral Selections
|
||||
|
||||
choice
|
||||
|
||||
@@ -54,6 +54,7 @@ CHIP_ASRCS = avrdx_exceptions.S
|
||||
CHIP_CSRCS = avrdx_lowconsole.c avrdx_lowinit.c avrdx_init.c
|
||||
CHIP_CSRCS += avrdx_serial.c avrdx_serial_early.c
|
||||
CHIP_CSRCS += avrdx_peripherals.c
|
||||
CHIP_CSRCS += avrdx_twi.c
|
||||
|
||||
# Configuration-dependent files
|
||||
|
||||
|
||||
1393
arch/avr/src/avrdx/avrdx_twi.c
Normal file
1393
arch/avr/src/avrdx/avrdx_twi.c
Normal file
File diff suppressed because it is too large
Load Diff
94
arch/avr/src/avrdx/avrdx_twi.h
Normal file
94
arch/avr/src/avrdx/avrdx_twi.h
Normal file
@@ -0,0 +1,94 @@
|
||||
/****************************************************************************
|
||||
* arch/avr/src/avrdx/avrdx_twi.h
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ARCH_AVR_SRC_AVRDX_AVRDX_TWI_H
|
||||
#define __ARCH_AVR_SRC_AVRDX_AVRDX_TWI_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include "avrdx_iodefs.h"
|
||||
#include <nuttx/i2c/i2c_master.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Base address of TWIn peripheral. TWI index corresponds to the location
|
||||
* of its I/O registers in memory. Ignores its parameter if the chip
|
||||
* only has one TWI.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_AVR_HAVE_TWI1
|
||||
# define AVRDX_TWI(n) (*(avr_twi_t *) (0x0900 + n * 0x20))
|
||||
#else
|
||||
# define AVRDX_TWI(n) (*(avr_twi_t *) (0x0900 + 0 * 0x20))
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Inline Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: avrdx_initialize_twi
|
||||
*
|
||||
* Description:
|
||||
* Initializer for TWI device. Allocates data structures and configures
|
||||
* the peripheral. May be called multiple times by multiple drivers using
|
||||
* the bus.
|
||||
*
|
||||
* Input Parameters:
|
||||
* Peripheral number, ignored if the chip only has single TWI
|
||||
*
|
||||
* Returned Value:
|
||||
* Initialized structure cast to i2c_master_s
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct i2c_master_s *avrdx_initialize_twi(uint8_t twi_n);
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __ARCH_AVR_SRC_AVRDX_AVRDX_TWI_H */
|
||||
@@ -52,6 +52,12 @@
|
||||
#define PORTMUX_USART2_NONE_GC (PORTMUX_USART2_1_bm | PORTMUX_USART2_0_bm)
|
||||
#define PORTMUX_USART2_GM (PORTMUX_USART2_1_bm | PORTMUX_USART2_0_bm)
|
||||
|
||||
/* PORTMUX.TWIROUTEA */
|
||||
|
||||
#define PORTMUX_TWI0_DEFAULT_GC (0)
|
||||
#define PORTMUX_TWI0_ALT2_GC = (PORTMUX_TWI0_1_bm)
|
||||
#define PORTMUX_TWI0_GM (PORTMUX_TWI0_1_bm | PORTMUX_TWI0_0_bm)
|
||||
|
||||
/* PORT.PINCONFIG */
|
||||
|
||||
#define PORT_ISC_GM ( PORT_ISC_0_bm | PORT_ISC_1_bm | PORT_ISC_2_bm )
|
||||
@@ -105,6 +111,35 @@
|
||||
#define USART_CHSIZE_7BIT_GC (USART_CHSIZE_1_bm)
|
||||
#define USART_CHSIZE_8BIT_GC (USART_CHSIZE_1_bm | USART_CHSIZE_0_bm)
|
||||
|
||||
/* TWI.MCTRLA */
|
||||
|
||||
#define TWI_FMPEN_ON_GC (TWI_FMPEN_bm)
|
||||
|
||||
#define TWI_SDAHOLD_OFF_GC (0)
|
||||
#define TWI_SDAHOLD_50NS_GC (TWI_SDAHOLD_0_bm)
|
||||
#define TWI_SDAHOLD_300NS_GC (TWI_SDAHOLD_1_bm)
|
||||
#define TWI_SDAHOLD_500NS_GC (TWI_SDAHOLD_1_bm | TWI_SDAHOLD_0_bm)
|
||||
|
||||
#define TWI_TIMEOUT_200US_GC (TWI_TIMEOUT_1_bm | TWI_TIMEOUT_0_bm)
|
||||
|
||||
/* TWI.MCTRLB */
|
||||
|
||||
#define TWI_MCMD_NOACT_GC (0)
|
||||
#define TWI_MCMD_REPSTART_GC (TWI_MCMD_0_bm)
|
||||
#define TWI_MCMD_RECVTRANS_GC (TWI_MCMD_1_bm)
|
||||
#define TWI_MCMD_STOP_GC (TWI_MCMD_0_bm | TWI_MCMD_1_bm)
|
||||
|
||||
#define TWI_ACKACT_ACK_GC (0)
|
||||
#define TWI_ACKACT_NACK_GC (TWI_ACKACT_bm)
|
||||
|
||||
/* TWI.MSTATUS */
|
||||
|
||||
#define TWI_BUSSTATE_UNKNOWN_GC (0)
|
||||
#define TWI_BUSSTATE_IDLE_GC (TWI_BUSSTATE_0_bm)
|
||||
#define TWI_BUSSTATE_OWNER_GC (TWI_BUSSTATE_1_bm)
|
||||
#define TWI_BUSSTATE_BUSY_GC (TWI_BUSSTATE_1_bm | TWI_BUSSTATE_0_bm)
|
||||
#define TWI_BUSSTATE_GM (TWI_BUSSTATE_1_bm | TWI_BUSSTATE_0_bm)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
@@ -130,6 +165,26 @@ typedef struct avr_usart_struct
|
||||
register8_t reserved_1[1];
|
||||
} avr_usart_t;
|
||||
|
||||
typedef struct avr_twi_struct
|
||||
{
|
||||
register8_t CTRLA; /* Control A */
|
||||
register8_t DUALCTRL; /* Dual Control */
|
||||
register8_t DBGCTRL; /* Debug Control Register */
|
||||
register8_t MCTRLA; /* Host Control A */
|
||||
register8_t MCTRLB; /* Host Control B */
|
||||
register8_t MSTATUS; /* Host Status */
|
||||
register8_t MBAUD; /* Host Baud Rate Control */
|
||||
register8_t MADDR; /* Host Address */
|
||||
register8_t MDATA; /* Host Data */
|
||||
register8_t SCTRLA; /* Client Control A */
|
||||
register8_t SCTRLB; /* Client Control B */
|
||||
register8_t SSTATUS; /* Client Status */
|
||||
register8_t SADDR; /* Client Address */
|
||||
register8_t SDATA; /* Client Data */
|
||||
register8_t SADDRMASK; /* Client Address Mask */
|
||||
register8_t reserved_1[1];
|
||||
} avr_twi_t;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
@@ -71,6 +71,18 @@
|
||||
#define PORTMUX_USART5_NONE_GC (PORTMUX_USART5_1_bm | PORTMUX_USART5_0_bm)
|
||||
#define PORTMUX_USART5_GM (PORTMUX_USART5_1_bm | PORTMUX_USART5_0_bm)
|
||||
|
||||
/* PORTMUX.TWIROUTEA */
|
||||
|
||||
#define PORTMUX_TWI0_DEFAULT_GC (0)
|
||||
#define PORTMUX_TWI0_ALT1_GC = (PORTMUX_TWI0_0_bm)
|
||||
#define PORTMUX_TWI0_ALT2_GC = (PORTMUX_TWI0_1_bm)
|
||||
#define PORTMUX_TWI0_GM (PORTMUX_TWI0_1_bm | PORTMUX_TWI0_0_bm)
|
||||
|
||||
#define PORTMUX_TWI1_DEFAULT_GC (0)
|
||||
#define PORTMUX_TWI1_ALT1_GC = (PORTMUX_TWI1_0_bm)
|
||||
#define PORTMUX_TWI1_ALT2_GC = (PORTMUX_TWI1_1_bm)
|
||||
#define PORTMUX_TWI1_GM (PORTMUX_TWI1_1_bm | PORTMUX_TWI1_0_bm)
|
||||
|
||||
/* PORT.PINCONFIG */
|
||||
|
||||
#define PORT_ISC_GM ( PORT_ISC_0_bm | PORT_ISC_1_bm | PORT_ISC_2_bm )
|
||||
@@ -124,6 +136,35 @@
|
||||
#define USART_CHSIZE_7BIT_GC (USART_CHSIZE_1_bm)
|
||||
#define USART_CHSIZE_8BIT_GC (USART_CHSIZE_1_bm | USART_CHSIZE_0_bm)
|
||||
|
||||
/* TWI.MCTRLA */
|
||||
|
||||
#define TWI_FMPEN_ON_GC (TWI_FMPEN_bm)
|
||||
|
||||
#define TWI_SDAHOLD_OFF_GC (0)
|
||||
#define TWI_SDAHOLD_50NS_GC (TWI_SDAHOLD_0_bm)
|
||||
#define TWI_SDAHOLD_300NS_GC (TWI_SDAHOLD_1_bm)
|
||||
#define TWI_SDAHOLD_500NS_GC (TWI_SDAHOLD_1_bm | TWI_SDAHOLD_0_bm)
|
||||
|
||||
#define TWI_TIMEOUT_200US_GC (TWI_TIMEOUT_1_bm | TWI_TIMEOUT_0_bm)
|
||||
|
||||
/* TWI.MCTRLB */
|
||||
|
||||
#define TWI_MCMD_NOACT_GC (0)
|
||||
#define TWI_MCMD_REPSTART_GC (TWI_MCMD_0_bm)
|
||||
#define TWI_MCMD_RECVTRANS_GC (TWI_MCMD_1_bm)
|
||||
#define TWI_MCMD_STOP_GC (TWI_MCMD_0_bm | TWI_MCMD_1_bm)
|
||||
|
||||
#define TWI_ACKACT_ACK_GC (0)
|
||||
#define TWI_ACKACT_NACK_GC (TWI_ACKACT_bm)
|
||||
|
||||
/* TWI.MSTATUS */
|
||||
|
||||
#define TWI_BUSSTATE_UNKNOWN_GC (0)
|
||||
#define TWI_BUSSTATE_IDLE_GC (TWI_BUSSTATE_0_bm)
|
||||
#define TWI_BUSSTATE_OWNER_GC (TWI_BUSSTATE_1_bm)
|
||||
#define TWI_BUSSTATE_BUSY_GC (TWI_BUSSTATE_1_bm | TWI_BUSSTATE_0_bm)
|
||||
#define TWI_BUSSTATE_GM (TWI_BUSSTATE_1_bm | TWI_BUSSTATE_0_bm)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
@@ -149,6 +190,26 @@ typedef struct avr_usart_struct
|
||||
register8_t reserved_1[1];
|
||||
} avr_usart_t;
|
||||
|
||||
typedef struct avr_twi_struct
|
||||
{
|
||||
register8_t CTRLA; /* Control A */
|
||||
register8_t DUALCTRL; /* Dual Control */
|
||||
register8_t DBGCTRL; /* Debug Control Register */
|
||||
register8_t MCTRLA; /* Host Control A */
|
||||
register8_t MCTRLB; /* Host Control B */
|
||||
register8_t MSTATUS; /* Host Status */
|
||||
register8_t MBAUD; /* Host Baud Rate Control */
|
||||
register8_t MADDR; /* Host Address */
|
||||
register8_t MDATA; /* Host Data */
|
||||
register8_t SCTRLA; /* Client Control A */
|
||||
register8_t SCTRLB; /* Client Control B */
|
||||
register8_t SSTATUS; /* Client Status */
|
||||
register8_t SADDR; /* Client Address */
|
||||
register8_t SDATA; /* Client Data */
|
||||
register8_t SADDRMASK; /* Client Address Mask */
|
||||
register8_t reserved_1[1];
|
||||
} avr_twi_t;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
@@ -71,6 +71,18 @@
|
||||
#define PORTMUX_USART5_NONE_GC (PORTMUX_USART5_1_bm | PORTMUX_USART5_0_bm)
|
||||
#define PORTMUX_USART5_GM (PORTMUX_USART5_1_bm | PORTMUX_USART5_0_bm)
|
||||
|
||||
/* PORTMUX.TWIROUTEA */
|
||||
|
||||
#define PORTMUX_TWI0_DEFAULT_GC (0)
|
||||
#define PORTMUX_TWI0_ALT1_GC = (PORTMUX_TWI0_0_bm)
|
||||
#define PORTMUX_TWI0_ALT2_GC = (PORTMUX_TWI0_1_bm)
|
||||
#define PORTMUX_TWI0_GM (PORTMUX_TWI0_1_bm | PORTMUX_TWI0_0_bm)
|
||||
|
||||
#define PORTMUX_TWI1_DEFAULT_GC (0)
|
||||
#define PORTMUX_TWI1_ALT1_GC = (PORTMUX_TWI1_0_bm)
|
||||
#define PORTMUX_TWI1_ALT2_GC = (PORTMUX_TWI1_1_bm)
|
||||
#define PORTMUX_TWI1_GM (PORTMUX_TWI1_1_bm | PORTMUX_TWI1_0_bm)
|
||||
|
||||
/* PORT.PINCONFIG */
|
||||
|
||||
#define PORT_ISC_GM ( PORT_ISC_0_bm | PORT_ISC_1_bm | PORT_ISC_2_bm )
|
||||
@@ -124,6 +136,35 @@
|
||||
#define USART_CHSIZE_7BIT_GC (USART_CHSIZE_1_bm)
|
||||
#define USART_CHSIZE_8BIT_GC (USART_CHSIZE_1_bm | USART_CHSIZE_0_bm)
|
||||
|
||||
/* TWI.MCTRLA */
|
||||
|
||||
#define TWI_FMPEN_ON_GC (TWI_FMPEN_bm)
|
||||
|
||||
#define TWI_SDAHOLD_OFF_GC (0)
|
||||
#define TWI_SDAHOLD_50NS_GC (TWI_SDAHOLD_0_bm)
|
||||
#define TWI_SDAHOLD_300NS_GC (TWI_SDAHOLD_1_bm)
|
||||
#define TWI_SDAHOLD_500NS_GC (TWI_SDAHOLD_1_bm | TWI_SDAHOLD_0_bm)
|
||||
|
||||
#define TWI_TIMEOUT_200US_GC (TWI_TIMEOUT_1_bm | TWI_TIMEOUT_0_bm)
|
||||
|
||||
/* TWI.MCTRLB */
|
||||
|
||||
#define TWI_MCMD_NOACT_GC (0)
|
||||
#define TWI_MCMD_REPSTART_GC (TWI_MCMD_0_bm)
|
||||
#define TWI_MCMD_RECVTRANS_GC (TWI_MCMD_1_bm)
|
||||
#define TWI_MCMD_STOP_GC (TWI_MCMD_0_bm | TWI_MCMD_1_bm)
|
||||
|
||||
#define TWI_ACKACT_ACK_GC (0)
|
||||
#define TWI_ACKACT_NACK_GC (TWI_ACKACT_bm)
|
||||
|
||||
/* TWI.MSTATUS */
|
||||
|
||||
#define TWI_BUSSTATE_UNKNOWN_GC (0)
|
||||
#define TWI_BUSSTATE_IDLE_GC (TWI_BUSSTATE_0_bm)
|
||||
#define TWI_BUSSTATE_OWNER_GC (TWI_BUSSTATE_1_bm)
|
||||
#define TWI_BUSSTATE_BUSY_GC (TWI_BUSSTATE_1_bm | TWI_BUSSTATE_0_bm)
|
||||
#define TWI_BUSSTATE_GM (TWI_BUSSTATE_1_bm | TWI_BUSSTATE_0_bm)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
@@ -149,6 +190,26 @@ typedef struct avr_usart_struct
|
||||
register8_t reserved_1[1];
|
||||
} avr_usart_t;
|
||||
|
||||
typedef struct avr_twi_struct
|
||||
{
|
||||
register8_t CTRLA; /* Control A */
|
||||
register8_t DUALCTRL; /* Dual Control */
|
||||
register8_t DBGCTRL; /* Debug Control Register */
|
||||
register8_t MCTRLA; /* Host Control A */
|
||||
register8_t MCTRLB; /* Host Control B */
|
||||
register8_t MSTATUS; /* Host Status */
|
||||
register8_t MBAUD; /* Host Baud Rate Control */
|
||||
register8_t MADDR; /* Host Address */
|
||||
register8_t MDATA; /* Host Data */
|
||||
register8_t SCTRLA; /* Client Control A */
|
||||
register8_t SCTRLB; /* Client Control B */
|
||||
register8_t SSTATUS; /* Client Status */
|
||||
register8_t SADDR; /* Client Address */
|
||||
register8_t SDATA; /* Client Data */
|
||||
register8_t SADDRMASK; /* Client Address Mask */
|
||||
register8_t reserved_1[1];
|
||||
} avr_twi_t;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
Reference in New Issue
Block a user