mbed-os
Fork of mbed-os by
features/unsupported/tests/peripherals/AT30TSE75X/AT30TSE75X.h@0:f269e3021894, 2016-10-23 (annotated)
- Committer:
- elessair
- Date:
- Sun Oct 23 15:10:02 2016 +0000
- Revision:
- 0:f269e3021894
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
elessair | 0:f269e3021894 | 1 | #ifndef AT30TSE75X_H |
elessair | 0:f269e3021894 | 2 | #define AT30TSE75X_H |
elessair | 0:f269e3021894 | 3 | |
elessair | 0:f269e3021894 | 4 | #include "mbed.h" |
elessair | 0:f269e3021894 | 5 | |
elessair | 0:f269e3021894 | 6 | #define AT30TSE_TEMPERATURE_TWI_ADDR (AT30TSE75X_DEVICE_TYPE_ID_TEMP | \ |
elessair | 0:f269e3021894 | 7 | (BOARD_AT30TSE_DEVICE_ADDR & 0x07)) |
elessair | 0:f269e3021894 | 8 | |
elessair | 0:f269e3021894 | 9 | /* AT30TSE75x Device Type ID for Temperature Sensor: 0b1001xxx */ |
elessair | 0:f269e3021894 | 10 | #define AT30TSE75X_DEVICE_TYPE_ID_TEMP 0x48 |
elessair | 0:f269e3021894 | 11 | /* AT30TSE75x Device Type ID for EEPROM: 0b1010xxx */ |
elessair | 0:f269e3021894 | 12 | #define AT30TSE75X_DEVICE_TYPE_ID_EEPROM 0x50 |
elessair | 0:f269e3021894 | 13 | |
elessair | 0:f269e3021894 | 14 | #define BOARD_AT30TSE_DEVICE_ADDR 0x07 /* 0b111 */ /*CAn be varied according to the condition of A0, A1, A2*/ |
elessair | 0:f269e3021894 | 15 | |
elessair | 0:f269e3021894 | 16 | #define AT30TSE_CONFIG_RES_9_bit 0 |
elessair | 0:f269e3021894 | 17 | #define AT30TSE_CONFIG_RES_10_bit 1 |
elessair | 0:f269e3021894 | 18 | #define AT30TSE_CONFIG_RES_11_bit 2 |
elessair | 0:f269e3021894 | 19 | #define AT30TSE_CONFIG_RES_12_bit 3 |
elessair | 0:f269e3021894 | 20 | |
elessair | 0:f269e3021894 | 21 | #define AT30TSE_TEMPERATURE_REG_SIZE 2 |
elessair | 0:f269e3021894 | 22 | |
elessair | 0:f269e3021894 | 23 | #if (BOARD_USING_AT30TSE != AT30TSE752) && \ |
elessair | 0:f269e3021894 | 24 | (BOARD_USING_AT30TSE != AT30TSE754) && \ |
elessair | 0:f269e3021894 | 25 | (BOARD_USING_AT30TSE != AT30TSE758) && \ |
elessair | 0:f269e3021894 | 26 | (BOARD_USING_AT30TSE != AT30TS75) |
elessair | 0:f269e3021894 | 27 | /* Using AT30TSE758 in Default */ |
elessair | 0:f269e3021894 | 28 | #define BOARD_USING_AT30TSE AT30TSE758 |
elessair | 0:f269e3021894 | 29 | #endif |
elessair | 0:f269e3021894 | 30 | |
elessair | 0:f269e3021894 | 31 | /* Setting the AT30TSE75x Temperature Sensor Address */ |
elessair | 0:f269e3021894 | 32 | #define AT30TSE_TEMPERATURE_TWI_ADDR (AT30TSE75X_DEVICE_TYPE_ID_TEMP | \ |
elessair | 0:f269e3021894 | 33 | (BOARD_AT30TSE_DEVICE_ADDR & 0x07)) |
elessair | 0:f269e3021894 | 34 | |
elessair | 0:f269e3021894 | 35 | #define AT30TSE752 1 |
elessair | 0:f269e3021894 | 36 | #define AT30TSE754 2 |
elessair | 0:f269e3021894 | 37 | #define AT30TSE758 3 |
elessair | 0:f269e3021894 | 38 | #define AT30TS75 4 |
elessair | 0:f269e3021894 | 39 | |
elessair | 0:f269e3021894 | 40 | #if BOARD_USING_AT30TSE == AT30TSE752 |
elessair | 0:f269e3021894 | 41 | #define AT30TSE_EEPROM_TWI_ADDR (AT30TSE75X_DEVICE_TYPE_ID_EEPROM | \ |
elessair | 0:f269e3021894 | 42 | (BOARD_AT30TSE_DEVICE_ADDR & 0x07)) |
elessair | 0:f269e3021894 | 43 | #elif BOARD_USING_AT30TSE == AT30TSE754 |
elessair | 0:f269e3021894 | 44 | #define AT30TSE_EEPROM_TWI_ADDR (AT30TSE75X_DEVICE_TYPE_ID_EEPROM | \ |
elessair | 0:f269e3021894 | 45 | (BOARD_AT30TSE_DEVICE_ADDR & 0x06)) |
elessair | 0:f269e3021894 | 46 | #elif BOARD_USING_AT30TSE == AT30TSE758 |
elessair | 0:f269e3021894 | 47 | #define AT30TSE_EEPROM_TWI_ADDR (AT30TSE75X_DEVICE_TYPE_ID_EEPROM | \ |
elessair | 0:f269e3021894 | 48 | (BOARD_AT30TSE_DEVICE_ADDR & 0x04)) |
elessair | 0:f269e3021894 | 49 | #elif BOARD_USING_AT30TSE != AT30TS75 |
elessair | 0:f269e3021894 | 50 | /* Using AT30TSE758 in Default */ |
elessair | 0:f269e3021894 | 51 | #define AT30TSE_EEPROM_TWI_ADDR (AT30TSE75X_DEVICE_TYPE_ID_EEPROM | \ |
elessair | 0:f269e3021894 | 52 | (BOARD_AT30TSE_DEVICE_ADDR & 0x04)) |
elessair | 0:f269e3021894 | 53 | #endif |
elessair | 0:f269e3021894 | 54 | |
elessair | 0:f269e3021894 | 55 | class AT30TSE75X |
elessair | 0:f269e3021894 | 56 | { |
elessair | 0:f269e3021894 | 57 | public: |
elessair | 0:f269e3021894 | 58 | AT30TSE75X(PinName sda, PinName scl); |
elessair | 0:f269e3021894 | 59 | ~AT30TSE75X(); |
elessair | 0:f269e3021894 | 60 | |
elessair | 0:f269e3021894 | 61 | float read_temp(); |
elessair | 0:f269e3021894 | 62 | uint8_t read_eeprom(uint8_t *data, uint8_t length, uint8_t word_addr, uint8_t page); |
elessair | 0:f269e3021894 | 63 | uint8_t write_eeprom(uint8_t *data, uint8_t length, uint8_t word_addr, uint8_t page); |
elessair | 0:f269e3021894 | 64 | |
elessair | 0:f269e3021894 | 65 | I2C at30tse75x_i2c; |
elessair | 0:f269e3021894 | 66 | private: |
elessair | 0:f269e3021894 | 67 | uint8_t resolution = AT30TSE_CONFIG_RES_9_bit; |
elessair | 0:f269e3021894 | 68 | |
elessair | 0:f269e3021894 | 69 | }; |
elessair | 0:f269e3021894 | 70 | |
elessair | 0:f269e3021894 | 71 | #endif |