circuitpython_dfrobot_gravity_drf0627_dual_uart

Author(s): Graham Beland, Sept. 2022 Implementation Notes ——————– Hardware: Software and Dependencies: * Adafruit CircuitPython <https://github.com/adafruit/circuitpython> * Bus Device <https://github.com/adafruit/Adafruit_CircuitPython_BusDevice> * Adafruit CircuitPython firmware for the supported boards: * https://circuitpython.org/downloads * Adafruit’s Bus Device library: * https://github.com/adafruit/Adafruit_CircuitPython_BusDevice

@file DFRobot_IIC_Serial.py @brief Define the basic structure of class DFRobot_IIC_Serial @n This is a library for IIC to UART module, the maximum rate is 1Mbps @n The band rate, word length, and check format @ of every sub UART can be set independently @n The module can provide at most 2Mbps communication rate @n Each sub UART is able to receive/transmit independent 256 bytes FIFO hardware cache @n Users can configure FIFO interrupt by programming.

@copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) @license The MIT License (MIT) @author [Arya](xue.peng@dfrobot.com) @version V1.1 @date 2021-05-07 @https://github.com/DFRobot/DFRobot_IIC_Serial

class circuitpython_dfrobot_gravity_drf0627_dual_uart.DFRobot_IIC_Serial(i2c, sub_uart_channel, IA1=1, IA0=1)

! @brief Constructor @param sub_uart_channel sub UART channel, @n WK2132 has two sub UARTs: SUBUART_CHANNEL_1 or SUBUART_CHANNEL_2 @param IA1: corresponds with IA1 Level(0 or 1) @n of DIP switch on the module, and is used for configuring @n the IIC address of the 6th bit value(default: 1). @param IA0: corresponds with IA0 Level(0 or 1) @n of DIP switch on the module, and is used for configuring @n IIC address of the 5th bit value(default: 1). @n IIC address configuration: @n 7 6 5 4 3 2 1 0 @n 0 IA1 IA0 1 0 C1 C0 0/1 @n IIC address only has 7 bits, while there are 8 bits @n for one byte, so the extra one bit will be filled as 0. @n The 6th bit corresponds with IA1 Level of DIP switch, @n can be configured manually. @n The 5th bit corresponds with IA0 Level of DIP switch, @n can be configured manually. @n The 4th and 3rd bits are fixed, value 1 and 0 respectively. @n The values of the 2nd and 1st bits are the sub UART channels, 00 for sub UART 1, 01 for sub UART 2. @n The 0 bit represents the operation object: 0 for register, 1 for FIFO cache.

OBJECT_FIFO = 1

Data format: N for no parity, Z for 0 parity, O for Odd parity, E for Even parity, F for 1 parity. 8 represents the number of data bit, 1 or 2 for the number of stop bit.

available()

! @brief Get the number of bytes in receive buffer, @n it should be the total number of bytes in FIFO @n receive buffer(256B) and self-defined _rx_buffer(31B). @return Return the number of bytes in receive buffer

begin(baud, theformat=0)

! @brief Init function, set sub UART band rate, data format @param baud: baud rate, it support: 9600, 57600, 115200, 2400, 4800, 7200, @n 14400, 19200, 28800,38400, 76800, 153600, 230400, 460800, 307200, 921600 @param format: Data format, it support: @n IIC_SERIAL_8N1, IIC_SERIAL_8N2, IIC_SERIAL_8Z1,IIC_SERIAL_8Z2 @n IIC_SERIAL_8O1, IIC_SERIAL_8O2, IIC_SERIAL_8E1, IIC_SERIAL_8E2 @n IIC_SERIAL_8F1, IIC_SERIAL_8F2 @return Return 0 if it sucess, otherwise return non-zero

end()

! @brief Release sub UART to clean up all registers in @n Sub UART. Call function begin() again to make it work.

flush()

! @brief Wait for the data to be transmited completely

peek()

! @brief Return the data of 1 byte without deleting the data in the receive buffer @return Return the readings

printf(*args, **kargs)

! @brief The Prints the values to a stream, usage is the same as print function. @param args @param kargs @n sep: string inserted between values, default a space. @n end: string appended after the last value, default a newline.

read(size=1)

! @brief Read size bytes from the serial port, @n this operation will delete the data in the buffer. @param size: the bytes of read @return less characters as requested.

write(value)

! @brief Output the given byte string over the serial port. @param value: byte string @return return bytes actually written.