⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aardvark.h

📁 电子盘DEMO板程序
💻 H
📖 第 1 页 / 共 2 页
字号:

/*
 * Read a stream of bytes from the I2C slave device.
 */
int aa_i2c_read (
    Aardvark     aardvark,
    aa_u16       slave_addr,
    AA_I2C_FLAGS flags,
    aa_u16       num_bytes,
    aa_u08 *     data_in
);


/*
 * Read a stream of bytes from the I2C slave device.
 * This API function returns the number of bytes read into
 * the num_read variable.  The return value of the function
 * is a status code.
 */
enum AA_I2C_STATUS {
    AA_I2C_STATUS_OK            = 0,
    AA_I2C_STATUS_BUS_ERROR     = 1,
    AA_I2C_STATUS_SLA_ACK       = 2,
    AA_I2C_STATUS_SLA_NACK      = 3,
    AA_I2C_STATUS_DATA_NACK     = 4,
    AA_I2C_STATUS_ARB_LOST      = 5,
    AA_I2C_STATUS_BUS_LOCKED    = 6,
    AA_I2C_STATUS_LAST_DATA_ACK = 7
};
#ifndef __cplusplus
typedef enum AA_I2C_STATUS AA_I2C_STATUS;
#endif

int aa_i2c_read_ext (
    Aardvark     aardvark,
    aa_u16       slave_addr,
    AA_I2C_FLAGS flags,
    aa_u16       num_bytes,
    aa_u08 *     data_in,
    aa_u16 *     num_read
);


/*
 * Write a stream of bytes to the I2C slave device.
 */
int aa_i2c_write (
    Aardvark       aardvark,
    aa_u16         slave_addr,
    AA_I2C_FLAGS   flags,
    aa_u16         num_bytes,
    const aa_u08 * data_out
);


/*
 * Write a stream of bytes to the I2C slave device.
 * This API function returns the number of bytes written into
 * the num_written variable.  The return value of the function
 * is a status code.
 */
int aa_i2c_write_ext (
    Aardvark       aardvark,
    aa_u16         slave_addr,
    AA_I2C_FLAGS   flags,
    aa_u16         num_bytes,
    const aa_u08 * data_out,
    aa_u16 *       num_written
);


/*
 * Enable/Disable the Aardvark as an I2C slave device
 */
int aa_i2c_slave_enable (
    Aardvark aardvark,
    aa_u08   addr,
    aa_u16   maxTxBytes,
    aa_u16   maxRxBytes
);


int aa_i2c_slave_disable (
    Aardvark aardvark
);


/*
 * Set the slave response in the event the Aardvark is put
 * into slave mode and contacted by a Master.
 */
int aa_i2c_slave_set_response (
    Aardvark       aardvark,
    aa_u08         num_bytes,
    const aa_u08 * data_out
);


/*
 * Return number of bytes written from a previous
 * Aardvark->I2C_master transmission.  Since the transmission is
 * happening asynchronously with respect to the PC host
 * software, there could be responses queued up from many
 * previous write transactions.
 */
int aa_i2c_slave_write_stats (
    Aardvark aardvark
);


/*
 * Read the bytes from an I2C slave reception
 */
int aa_i2c_slave_read (
    Aardvark aardvark,
    aa_u08 * addr,
    aa_u16   num_bytes,
    aa_u08 * data_in
);


/*
 * Extended functions that return status code    
 */
int aa_i2c_slave_write_stats_ext (
    Aardvark aardvark,
    aa_u16 * num_written
);


int aa_i2c_slave_read_ext (
    Aardvark aardvark,
    aa_u08 * addr,
    aa_u16   num_bytes,
    aa_u08 * data_in,
    aa_u16 * num_read
);


/*
 * Enable the I2C bus monitor
 * This disables all other functions on the Aardvark adapter
 */
int aa_i2c_monitor_enable (
    Aardvark aardvark
);


/*
 * Disable the I2C bus monitor
 */
int aa_i2c_monitor_disable (
    Aardvark aardvark
);


/*
 * Read the data collected by the bus monitor
 */
#define AA_I2C_MONITOR_DATA 0x00ff
#define AA_I2C_MONITOR_NACK 0x0100
#define AA_I2C_MONITOR_CMD_START 0xff00
#define AA_I2C_MONITOR_CMD_STOP 0xff01
int aa_i2c_monitor_read (
    Aardvark aardvark,
    aa_u16   num_bytes,
    aa_u16 * data
);


/*
 * Configure the I2C pullup resistors.
 * This is only supported on hardware versions >= 2.00
 */
#define AA_I2C_PULLUP_NONE 0x00
#define AA_I2C_PULLUP_BOTH 0x03
#define AA_I2C_PULLUP_QUERY 0x80
int aa_i2c_pullup (
    Aardvark aardvark,
    aa_u08   pullup_mask
);



/*=========================================================================
| SPI API
 ========================================================================*/
/*
 * Set the SPI bit rate in kilohertz.  If a zero is passed as the
 * bitrate, the bitrate is unchanged and the current bitrate is
 * returned.
 */
int aa_spi_bitrate (
    Aardvark aardvark,
    int      bitrate_khz
);


/*
 * These configuration parameters specify how to clock the
 * bits that are sent and received on the Aardvark SPI
 * interface.
 * 
 *   The polarity option specifies which transition
 *   constitutes the leading edge and which transition is the
 *   falling edge.  For example, AA_SPI_POL_RISING_FALLING
 *   would configure the SPI to idle the SCK clock line low.
 *   The clock would then transition low-to-high on the
 *   leading edge and high-to-low on the trailing edge.
 * 
 *   The phase option determines whether to sample or setup on
 *   the leading edge.  For example, AA_SPI_PHASE_SAMPLE_SETUP
 *   would configure the SPI to sample on the leading edge and
 *   setup on the trailing edge.
 * 
 *   The bitorder option is used to indicate whether LSB or
 *   MSB is shifted first.
 * 
 * See the diagrams in the Aardvark datasheet for
 * more details.
 */
enum AA_SPI_POLARITY {
    AA_SPI_POL_RISING_FALLING = 0,
    AA_SPI_POL_FALLING_RISING = 1
};
#ifndef __cplusplus
typedef enum AA_SPI_POLARITY AA_SPI_POLARITY;
#endif

enum AA_SPI_PHASE {
    AA_SPI_PHASE_SAMPLE_SETUP = 0,
    AA_SPI_PHASE_SETUP_SAMPLE = 1
};
#ifndef __cplusplus
typedef enum AA_SPI_PHASE AA_SPI_PHASE;
#endif

enum AA_SPI_BITORDER {
    AA_SPI_BITORDER_MSB = 0,
    AA_SPI_BITORDER_LSB = 1
};
#ifndef __cplusplus
typedef enum AA_SPI_BITORDER AA_SPI_BITORDER;
#endif

/*
 * Configure the SPI master or slave interface
 */
int aa_spi_configure (
    Aardvark        aardvark,
    AA_SPI_POLARITY polarity,
    AA_SPI_PHASE    phase,
    AA_SPI_BITORDER bitorder
);


/*
 * Write a stream of bytes to the downstream SPI slave device.
 */
int aa_spi_write (
    Aardvark       aardvark,
    aa_u16         num_bytes,
    const aa_u08 * data_out,
    aa_u08 *       data_in
);


/*
 * Enable/Disable the Aardvark as an SPI slave device
 */
int aa_spi_slave_enable (
    Aardvark aardvark
);


int aa_spi_slave_disable (
    Aardvark aardvark
);


/*
 * Set the slave response in the event the Aardvark is put
 * into slave mode and contacted by a Master.
 */
int aa_spi_slave_set_response (
    Aardvark       aardvark,
    aa_u08         num_bytes,
    const aa_u08 * data_out
);


/*
 * Read the bytes from an SPI slave reception
 */
int aa_spi_slave_read (
    Aardvark aardvark,
    aa_u16   num_bytes,
    aa_u08 * data_in
);


/*
 * Change the output polarity on the SS line.
 * 
 * Note: When configured as an SPI slave, the Aardvark will
 * always be setup with SS as active low.  Hence this function
 * only affects the SPI master functions on the Aardvark.
 */
enum AA_SPI_SS_POLARITY {
    AA_SPI_SS_ACTIVE_LOW  = 0,
    AA_SPI_SS_ACTIVE_HIGH = 1
};
#ifndef __cplusplus
typedef enum AA_SPI_SS_POLARITY AA_SPI_SS_POLARITY;
#endif

int aa_spi_master_ss_polarity (
    Aardvark           aardvark,
    AA_SPI_SS_POLARITY polarity
);



/*=========================================================================
| GPIO API
 ========================================================================*/
/*
 * The following enumerated type maps the named lines on the
 * Aardvark I2C/SPI line to bit positions in the GPIO API.
 * All GPIO API functions will index these lines through an
 * 8-bit masked value.  Thus, each bit position in the mask
 * can be referred back its corresponding line through the
 * enumerated type.
 */
enum AA_GPIO_BITS {
    AA_GPIO_SCL  = 0x01,
    AA_GPIO_SDA  = 0x02,
    AA_GPIO_MISO = 0x04,
    AA_GPIO_SCK  = 0x08,
    AA_GPIO_MOSI = 0x10,
    AA_GPIO_SS   = 0x20
};
#ifndef __cplusplus
typedef enum AA_GPIO_BITS AA_GPIO_BITS;
#endif

/*
 * Configure the GPIO, specifying the direction of each bit.
 * 
 * A call to this function will not change the value of the pullup
 * mask in the Aardvark.  This is illustrated by the following
 * example:
 *   (1) Direction mask is first set to 0x00
 *   (2) Pullup is set to 0x01
 *   (3) Direction mask is set to 0x01
 *   (4) Direction mask is later set back to 0x00.
 * 
 * The pullup will be active after (4).
 * 
 * On Aardvark power-up, the default value of the direction
 * mask is 0x00.
 */
#define AA_GPIO_DIR_INPUT 0
#define AA_GPIO_DIR_OUTPUT 1
int aa_gpio_direction (
    Aardvark aardvark,
    aa_u08   direction_mask
);


/*
 * Enable an internal pullup on any of the GPIO input lines.
 * 
 * Note: If a line is configured as an output, the pullup bit
 * for that line will be ignored, though that pullup bit will
 * be cached in case the line is later configured as an input.
 * 
 * By default the pullup mask is 0x00.
 */
#define AA_GPIO_PULLUP_OFF 0
#define AA_GPIO_PULLUP_ON 1
int aa_gpio_pullup (
    Aardvark aardvark,
    aa_u08   pullup_mask
);


/*
 * Read the current digital values on the GPIO input lines.
 * 
 * The bits will be ordered as described by AA_GPIO_BITS.  If a
 * line is configured as an output, its corresponding bit
 * position in the mask will be undefined.
 */
int aa_gpio_get (
    Aardvark aardvark
);


/*
 * Set the outputs on the GPIO lines.
 * 
 * Note: If a line is configured as an input, it will not be
 * affected by this call, but the output value for that line
 * will be cached in the event that the line is later
 * configured as an output.
 */
int aa_gpio_set (
    Aardvark aardvark,
    aa_u08   value
);




#ifdef __cplusplus
}
#endif

#endif  /* __aardvark_h__ */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -