Dependencies:   USBDevice

Committer:
walterluu
Date:
Wed Dec 29 06:43:21 2021 +0000
Revision:
32:51535920edd1
PICO_OT07_Firmware;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
walterluu 32:51535920edd1 1 #include "mbed.h"
walterluu 32:51535920edd1 2
walterluu 32:51535920edd1 3 //OT07 Registers
walterluu 32:51535920edd1 4 #define OT07_STATUS 0x00 // OT07 status regiter
walterluu 32:51535920edd1 5 #define OT07_INT_EN 0x01 // OT07 Interrupt Enable
walterluu 32:51535920edd1 6 #define OT07_FIFO_W 0x04 // OT07 FIFO Write Pointer
walterluu 32:51535920edd1 7 #define OT07_FIFO_R 0x05 // OT07 FIFO Read Pointer
walterluu 32:51535920edd1 8 #define OT07_FIFO_OF 0x06 // OT07 FIFO Overflow Counter
walterluu 32:51535920edd1 9 #define OT07_FIFO_COUNT 0x07 // OT07 FIFO Data Count
walterluu 32:51535920edd1 10 #define OT07_FIFO_DATA 0x08 // OT07 FIFO Data
walterluu 32:51535920edd1 11 #define OT07_FIFO_CNFG1 0x09 // OT07 FIFO Configuration 1 (FIFO_A_FULL)
walterluu 32:51535920edd1 12 #define OT07_FIFO_CNFG2 0x0A // OT07 FIFO Configuration 2
walterluu 32:51535920edd1 13 #define OT07_SYS 0x0C // OT07 System Configuration
walterluu 32:51535920edd1 14 #define OT07_ALARM_HIGH_MSB 0x10 // OT07 Alarm High MSB
walterluu 32:51535920edd1 15 #define OT07_ALARM_HIGH_LSB 0x11 // OT07 Alarm High LSB
walterluu 32:51535920edd1 16 #define OT07_ALARM_LOW_MSB 0x12 // OT07 Alarm Low MSB
walterluu 32:51535920edd1 17 #define OT07_ALARM_LOW_LSB 0x13 // OT07 Alarm LOW LSB
walterluu 32:51535920edd1 18 #define OT07_ADC_SETUP 0x14 // OT07 Temp Seneor Setup (ADC_RES[7:6]) & Convert Temperature [0]
walterluu 32:51535920edd1 19 #define OT07_GPIO_SETUP 0x20 // OT07 GPIO Setup, sets GPIO modes
walterluu 32:51535920edd1 20 #define OT07_GPIO_CTRL 0x21 // OT07 GPIO control
walterluu 32:51535920edd1 21 #define OT07_ROM_ID 0x31 // OT07 ROM_ID address of LSB?
walterluu 32:51535920edd1 22
walterluu 32:51535920edd1 23 #define DEVICE_ACK 0
walterluu 32:51535920edd1 24 #define DEVICE_NACK 1
walterluu 32:51535920edd1 25 #define DEVICE_BAD_RESP 2
walterluu 32:51535920edd1 26
walterluu 32:51535920edd1 27 #define MAX_DEVICES 64 // Maximum number of rom devices allowed
walterluu 32:51535920edd1 28 #define ID_LENGTH 6 // Rom ID length in bytes
walterluu 32:51535920edd1 29
walterluu 32:51535920edd1 30 struct OT07_struct {
walterluu 32:51535920edd1 31 char rom_id[ID_LENGTH]; // device ROM ID
walterluu 32:51535920edd1 32 char I2C_address; // I2C addess, based on GPIO0 and GPIO1 at power up
walterluu 32:51535920edd1 33 // Why char?
walterluu 32:51535920edd1 34 };
walterluu 32:51535920edd1 35
walterluu 32:51535920edd1 36 struct TempResponse {
walterluu 32:51535920edd1 37 double tempC; // Temperature in °C
walterluu 32:51535920edd1 38 int status; // Status of Temperature read. 0 for success, 1 for error
walterluu 32:51535920edd1 39 };
walterluu 32:51535920edd1 40
walterluu 32:51535920edd1 41 // *****************************************************************************
walterluu 32:51535920edd1 42 // OT07_write_register(char, char, char) writes single byte to OT07
walterluu 32:51535920edd1 43 // char I2C address
walterluu 32:51535920edd1 44 // char OT07 register address
walterluu 32:51535920edd1 45 // char data byte to be writen
walterluu 32:51535920edd1 46 // returns 0 on success ACK, 1 on NACK
walterluu 32:51535920edd1 47 // *****************************************************************************
walterluu 32:51535920edd1 48 int OT07_write_register(I2C *i2c, char I2C_add, char reg_add, char byte);
walterluu 32:51535920edd1 49
walterluu 32:51535920edd1 50 /// ****************************************************************************
walterluu 32:51535920edd1 51 // OT07_write_register(char, char, char *, int) writes multiple bytes to OT07
walterluu 32:51535920edd1 52 // char I2C address
walterluu 32:51535920edd1 53 // char OT07 register address
walterluu 32:51535920edd1 54 // char * data vector of bytes to be written
walterluu 32:51535920edd1 55 // int number of bytes to write
walterluu 32:51535920edd1 56 // returns 0 on success ACK, 1 on NACK
walterluu 32:51535920edd1 57 // *****************************************************************************
walterluu 32:51535920edd1 58 int OT07_write_register(I2C *i2c, char I2C_add, char reg_add, char *bytes, int n);
walterluu 32:51535920edd1 59
walterluu 32:51535920edd1 60 // *****************************************************************************
walterluu 32:51535920edd1 61 // OT07_read_register(char, char, char *, int) writes single byte to OT07
walterluu 32:51535920edd1 62 // char I2C address
walterluu 32:51535920edd1 63 // char OT07 register address
walterluu 32:51535920edd1 64 // char * data vector for read bytes to be stored in
walterluu 32:51535920edd1 65 // int number of bytes to read
walterluu 32:51535920edd1 66 // returns 0 on success, 1 on fail
walterluu 32:51535920edd1 67 // *****************************************************************************
walterluu 32:51535920edd1 68 int OT07_read_register(I2C *i2c, char I2C_add, char reg_add, char *bytes, int n);
walterluu 32:51535920edd1 69
walterluu 32:51535920edd1 70 // *****************************************************************************
walterluu 32:51535920edd1 71 // convert_temperature(char) sends convert command to OT07 device
walterluu 32:51535920edd1 72 // char I2C address
walterluu 32:51535920edd1 73 // *****************************************************************************
walterluu 32:51535920edd1 74 void convert_temperature(I2C *i2c, char I2C_add);
walterluu 32:51535920edd1 75
walterluu 32:51535920edd1 76 //******************************************************************************
walterluu 32:51535920edd1 77 // get_temperature(char) read temperature from OT07 device FIFO register
walterluu 32:51535920edd1 78 // char I2C address
walterluu 32:51535920edd1 79 // returns TempResponse tempC = temperature in oC
walterluu 32:51535920edd1 80 // status = register read result
walterluu 32:51535920edd1 81 //******************************************************************************
walterluu 32:51535920edd1 82 TempResponse get_temperature(I2C *i2c, char I2C_add);