LibDriver STTS22H
Loading...
Searching...
No Matches
driver_stts22h_basic.c
Go to the documentation of this file.
1
36
38
39static stts22h_handle_t gs_handle;
40
50{
51 uint8_t res;
52
53 /* link interface function */
62
63 /* set addr pin */
64 res = stts22h_set_addr_pin(&gs_handle, addr_pin);
65 if (res != 0)
66 {
67 stts22h_interface_debug_print("stts22h: set addr pin failed.\n");
68
69 return 1;
70 }
71
72 /* stts22h init */
73 res = stts22h_init(&gs_handle);
74 if (res != 0)
75 {
76 stts22h_interface_debug_print("stts22h: init failed.\n");
77
78 return 1;
79 }
80
81 /* set default smbus timeout */
83 if (res != 0)
84 {
85 stts22h_interface_debug_print("stts22h: set disable smbus timeout failed.\n");
86 (void)stts22h_deinit(&gs_handle);
87
88 return 1;
89 }
90
91 /* set default block data update */
93 if (res != 0)
94 {
95 stts22h_interface_debug_print("stts22h: set block data update failed.\n");
96 (void)stts22h_deinit(&gs_handle);
97
98 return 1;
99 }
100
101 /* set default iic address auto increment */
103 if (res != 0)
104 {
105 stts22h_interface_debug_print("stts22h: set iic address auto increment failed.\n");
106 (void)stts22h_deinit(&gs_handle);
107
108 return 1;
109 }
110
111 /* set default output data rate */
113 if (res != 0)
114 {
115 stts22h_interface_debug_print("stts22h: set output data rate failed.\n");
116 (void)stts22h_deinit(&gs_handle);
117
118 return 1;
119 }
120
121 /* start continuous read */
122 res = stts22h_start_continuous_read(&gs_handle);
123 if (res != 0)
124 {
125 stts22h_interface_debug_print("stts22h: start continuous read failed.\n");
126 (void)stts22h_deinit(&gs_handle);
127
128 return 1;
129 }
130
131 return 0;
132}
133
142uint8_t stts22h_basic_read(float *celsius_deg)
143{
144 int16_t raw;
145
146 /* read data */
147 if (stts22h_continuous_read(&gs_handle, &raw, celsius_deg) != 0)
148 {
149 return 1;
150 }
151
152 return 0;
153}
154
163{
164 uint8_t res;
165
166 /* stop continuous read*/
167 res = stts22h_stop_continuous_read(&gs_handle);
168 if (res != 0)
169 {
170 return 1;
171 }
172
173 /* close stts22h */
174 if (stts22h_deinit(&gs_handle) != 0)
175 {
176 return 1;
177 }
178
179 return 0;
180}
driver stts22h basic header file
uint8_t stts22h_init(stts22h_handle_t *handle)
initialize the chip
uint8_t stts22h_stop_continuous_read(stts22h_handle_t *handle)
stop the chip reading
uint8_t stts22h_set_iic_address_auto_increment(stts22h_handle_t *handle, stts22h_bool_t enable)
enable or disable iic address auto increment
struct stts22h_handle_s stts22h_handle_t
stts22h handle structure definition
uint8_t stts22h_set_addr_pin(stts22h_handle_t *handle, stts22h_address_t addr_pin)
set the iic address pin
uint8_t stts22h_set_output_data_rate(stts22h_handle_t *handle, stts22h_output_data_rate_t rate)
set output data rate
uint8_t stts22h_deinit(stts22h_handle_t *handle)
close the chip
uint8_t stts22h_set_block_data_update(stts22h_handle_t *handle, stts22h_bool_t enable)
enable or disable block data update
uint8_t stts22h_set_disable_smbus_timeout(stts22h_handle_t *handle, stts22h_bool_t enable)
enable or disable disable smbus timeout
uint8_t stts22h_continuous_read(stts22h_handle_t *handle, int16_t *raw, float *celsius_deg)
read data from the chip continuously
stts22h_address_t
stts22h address enumeration definition
uint8_t stts22h_start_continuous_read(stts22h_handle_t *handle)
start the chip reading
#define STTS22H_BASIC_DEFAULT_OUTPUT_DATA_RATE
uint8_t stts22h_basic_read(float *celsius_deg)
basic example read
uint8_t stts22h_basic_deinit(void)
basic example deinit
#define STTS22H_BASIC_DEFAULT_IIC_ADDRESS_AUTO_INCREMENT
uint8_t stts22h_basic_init(stts22h_address_t addr_pin)
basic example init
#define STTS22H_BASIC_DEFAULT_BLOCK_DATA_UPDATE
#define STTS22H_BASIC_DEFAULT_DISABLE_SMBUS_TIMEOUT
stts22h basic example default definition
uint8_t stts22h_interface_iic_deinit(void)
interface iic bus deinit
void stts22h_interface_delay_ms(uint32_t ms)
interface delay ms
void stts22h_interface_receive_callback(uint8_t type)
interface receive callback
uint8_t stts22h_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
void stts22h_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t stts22h_interface_iic_init(void)
interface iic bus init
uint8_t stts22h_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read