📄 aardvark.bas
字号:
Public Function aa_i2c_slave_set_response (ByVal aardvark As Long, ByRef data_out() As Byte) as Long
If check_version() Then
Dim num_bytes As Long
num_bytes = UBound(data_out) - LBound(data_out) + 1
aa_i2c_slave_set_response = std_aa_i2c_slave_set_response(aardvark, num_bytes, data_out(0))
Else
aa_i2c_slave_set_response = AA_INCOMPATIBLE_LIBRARY
End If
End Function
' 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.
Public Function aa_i2c_slave_write_stats (ByVal aardvark As Long) as Long
If check_version() Then
aa_i2c_slave_write_stats = std_aa_i2c_slave_write_stats(aardvark)
Else
aa_i2c_slave_write_stats = AA_INCOMPATIBLE_LIBRARY
End If
End Function
' Read the bytes from an I2C slave reception
Public Function aa_i2c_slave_read (ByVal aardvark As Long, ByRef addr As Byte, ByVal num_bytes As Integer, ByRef data_in() As Byte) as Long
If check_version() Then
aa_i2c_slave_read = std_aa_i2c_slave_read(aardvark, addr, num_bytes, data_in(0))
Else
aa_i2c_slave_read = AA_INCOMPATIBLE_LIBRARY
End If
End Function
' Extended functions that return status code
Public Function aa_i2c_slave_write_stats_ext (ByVal aardvark As Long, ByRef num_written As Integer) as Long
If check_version() Then
aa_i2c_slave_write_stats_ext = std_aa_i2c_slave_write_stats_ext(aardvark, num_written)
Else
aa_i2c_slave_write_stats_ext = AA_INCOMPATIBLE_LIBRARY
End If
End Function
Public Function aa_i2c_slave_read_ext (ByVal aardvark As Long, ByRef addr As Byte, ByVal num_bytes As Integer, ByRef data_in() As Byte, ByRef num_read As Integer) as Long
If check_version() Then
aa_i2c_slave_read_ext = std_aa_i2c_slave_read_ext(aardvark, addr, num_bytes, data_in(0), num_read)
Else
aa_i2c_slave_read_ext = AA_INCOMPATIBLE_LIBRARY
End If
End Function
' Enable the I2C bus monitor
' This disables all other functions on the Aardvark adapter
Public Function aa_i2c_monitor_enable (ByVal aardvark As Long) as Long
If check_version() Then
aa_i2c_monitor_enable = std_aa_i2c_monitor_enable(aardvark)
Else
aa_i2c_monitor_enable = AA_INCOMPATIBLE_LIBRARY
End If
End Function
' Disable the I2C bus monitor
Public Function aa_i2c_monitor_disable (ByVal aardvark As Long) as Long
If check_version() Then
aa_i2c_monitor_disable = std_aa_i2c_monitor_disable(aardvark)
Else
aa_i2c_monitor_disable = AA_INCOMPATIBLE_LIBRARY
End If
End Function
' Read the data collected by the bus monitor
Public Function aa_i2c_monitor_read (ByVal aardvark As Long, ByVal num_bytes As Integer, ByRef data() As Integer) as Long
If check_version() Then
aa_i2c_monitor_read = std_aa_i2c_monitor_read(aardvark, num_bytes, data(0))
Else
aa_i2c_monitor_read = AA_INCOMPATIBLE_LIBRARY
End If
End Function
' Configure the I2C pullup resistors.
' This is only supported on hardware versions >= 2.00
Public Function aa_i2c_pullup (ByVal aardvark As Long, ByVal pullup_mask As Byte) as Long
If check_version() Then
aa_i2c_pullup = std_aa_i2c_pullup(aardvark, pullup_mask)
Else
aa_i2c_pullup = AA_INCOMPATIBLE_LIBRARY
End If
End Function
'==========================================================================
' 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.
Public Function aa_spi_bitrate (ByVal aardvark As Long, ByVal bitrate_khz As Long) as Long
If check_version() Then
aa_spi_bitrate = std_aa_spi_bitrate(aardvark, bitrate_khz)
Else
aa_spi_bitrate = AA_INCOMPATIBLE_LIBRARY
End If
End Function
' 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.
' Configure the SPI master or slave interface
Public Function aa_spi_configure (ByVal aardvark As Long, ByVal polarity As Long, ByVal phase As Long, ByVal bitorder As Long) as Long
If check_version() Then
aa_spi_configure = std_aa_spi_configure(aardvark, polarity, phase, bitorder)
Else
aa_spi_configure = AA_INCOMPATIBLE_LIBRARY
End If
End Function
' Write a stream of bytes to the downstream SPI slave device.
Public Function aa_spi_write (ByVal aardvark As Long, ByRef data_out() As Byte, ByRef data_in() As Byte) as Long
If check_version() Then
Dim num_bytes As Long
num_bytes = UBound(data_out) - LBound(data_out) + 1
aa_spi_write = std_aa_spi_write(aardvark, num_bytes, data_out(0), data_in(0))
Else
aa_spi_write = AA_INCOMPATIBLE_LIBRARY
End If
End Function
' Enable/Disable the Aardvark as an SPI slave device
Public Function aa_spi_slave_enable (ByVal aardvark As Long) as Long
If check_version() Then
aa_spi_slave_enable = std_aa_spi_slave_enable(aardvark)
Else
aa_spi_slave_enable = AA_INCOMPATIBLE_LIBRARY
End If
End Function
Public Function aa_spi_slave_disable (ByVal aardvark As Long) as Long
If check_version() Then
aa_spi_slave_disable = std_aa_spi_slave_disable(aardvark)
Else
aa_spi_slave_disable = AA_INCOMPATIBLE_LIBRARY
End If
End Function
' Set the slave response in the event the Aardvark is put
' into slave mode and contacted by a Master.
Public Function aa_spi_slave_set_response (ByVal aardvark As Long, ByRef data_out() As Byte) as Long
If check_version() Then
Dim num_bytes As Long
num_bytes = UBound(data_out) - LBound(data_out) + 1
aa_spi_slave_set_response = std_aa_spi_slave_set_response(aardvark, num_bytes, data_out(0))
Else
aa_spi_slave_set_response = AA_INCOMPATIBLE_LIBRARY
End If
End Function
' Read the bytes from an SPI slave reception
Public Function aa_spi_slave_read (ByVal aardvark As Long, ByVal num_bytes As Integer, ByRef data_in() As Byte) as Long
If check_version() Then
aa_spi_slave_read = std_aa_spi_slave_read(aardvark, num_bytes, data_in(0))
Else
aa_spi_slave_read = AA_INCOMPATIBLE_LIBRARY
End If
End Function
' 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.
Public Function aa_spi_master_ss_polarity (ByVal aardvark As Long, ByVal polarity As Long) as Long
If check_version() Then
aa_spi_master_ss_polarity = std_aa_spi_master_ss_polarity(aardvark, polarity)
Else
aa_spi_master_ss_polarity = AA_INCOMPATIBLE_LIBRARY
End If
End Function
'==========================================================================
' 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.
' 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.
Public Function aa_gpio_direction (ByVal aardvark As Long, ByVal direction_mask As Byte) as Long
If check_version() Then
aa_gpio_direction = std_aa_gpio_direction(aardvark, direction_mask)
Else
aa_gpio_direction = AA_INCOMPATIBLE_LIBRARY
End If
End Function
' 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.
Public Function aa_gpio_pullup (ByVal aardvark As Long, ByVal pullup_mask As Byte) as Long
If check_version() Then
aa_gpio_pullup = std_aa_gpio_pullup(aardvark, pullup_mask)
Else
aa_gpio_pullup = AA_INCOMPATIBLE_LIBRARY
End If
End Function
' 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.
Public Function aa_gpio_get (ByVal aardvark As Long) as Long
If check_version() Then
aa_gpio_get = std_aa_gpio_get(aardvark)
Else
aa_gpio_get = AA_INCOMPATIBLE_LIBRARY
End If
End Function
' 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.
Public Function aa_gpio_set (ByVal aardvark As Long, ByVal value As Byte) as Long
If check_version() Then
aa_gpio_set = std_aa_gpio_set(aardvark, value)
Else
aa_gpio_set = AA_INCOMPATIBLE_LIBRARY
End If
End Function
' Block until there is a change on the GPIO input lines.
' Pins configured as outputs will be ignored.
'
' The function will return either when a change has occurred or
' the timeout expires. The timeout, specified in millisecods, has
' a precision of ~16 ms. The maximum allowable timeout is
' approximately 4 seconds. If the timeout expires, this function
' will return the current state of the GPIO lines.
'
' This function will return immediately with the current value
' of the GPIO lines for the first invocation after any of the
' following functions are called: aa_configure,
' aa_gpio_direction, or aa_gpio_pullup.
'
' If the function aa_gpio_get is called before calling
' aa_gpio_change, aa_gpio_change will only register any changes
' from the value last returned by aa_gpio_get.
Public Function aa_gpio_change (ByVal aardvark As Long, ByVal timeout As Integer) as Long
If check_version() Then
aa_gpio_change = std_aa_gpio_change(aardvark, timeout)
Else
aa_gpio_change = AA_INCOMPATIBLE_LIBRARY
End If
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -