LibDriver APM2000
Loading...
Searching...
No Matches
driver_apm2000_basic.c
Go to the documentation of this file.
1
36
38
39static apm2000_handle_t gs_handle;
40
50{
51 uint8_t res;
52
53 /* link functions */
66
67 /* set the interface */
68 res = apm2000_set_interface(&gs_handle, interface);
69 if (res != 0)
70 {
71 apm2000_interface_debug_print("apm2000: set interface failed.\n");
72
73 return 1;
74 }
75
76 /* init the chip */
77 res = apm2000_init(&gs_handle);
78 if (res != 0)
79 {
80 apm2000_interface_debug_print("apm2000: init failed.\n");
81
82 return 1;
83 }
84
85 if (interface == APM2000_INTERFACE_IIC)
86 {
87 /* start measurement */
88 res = apm2000_start_measurement(&gs_handle);
89 if (res != 0)
90 {
91 apm2000_interface_debug_print("apm2000: start measurement failed.\n");
92 (void)apm2000_deinit(&gs_handle);
93
94 return 1;
95 }
96 }
97
98 return 0;
99}
100
109{
110 uint8_t res;
111 apm2000_interface_t interface;
112
113 /* get interface */
114 res = apm2000_get_interface(&gs_handle, &interface);
115 if (res != 0)
116 {
117 return 1;
118 }
119
120 if (interface == APM2000_INTERFACE_IIC)
121 {
122 /* stop measurement */
123 res = apm2000_stop_measurement(&gs_handle);
124 if (res != 0)
125 {
126 return 1;
127 }
128 }
129
130 /* deinit */
131 res = apm2000_deinit(&gs_handle);
132 if (res != 0)
133 {
134 return 1;
135 }
136
137 return 0;
138}
139
149{
150 uint8_t res;
151
152 /* read data */
153 res = apm2000_read(&gs_handle, pm);
154 if (res != 0)
155 {
156 return 1;
157 }
158
159 return 0;
160}
driver apm2000 basic header file
uint8_t apm2000_deinit(apm2000_handle_t *handle)
close the chip
struct apm2000_pm_s apm2000_pm_t
apm2000 pm structure definition
uint8_t apm2000_get_interface(apm2000_handle_t *handle, apm2000_interface_t *interface)
get the chip interface
uint8_t apm2000_set_interface(apm2000_handle_t *handle, apm2000_interface_t interface)
set the chip interface
uint8_t apm2000_stop_measurement(apm2000_handle_t *handle)
stop the measurement
struct apm2000_handle_s apm2000_handle_t
apm2000 handle structure definition
uint8_t apm2000_init(apm2000_handle_t *handle)
initialize the chip
apm2000_interface_t
apm2000 interface enumeration definition
uint8_t apm2000_start_measurement(apm2000_handle_t *handle)
start the measurement
uint8_t apm2000_read(apm2000_handle_t *handle, apm2000_pm_t *pm)
read the result
@ APM2000_INTERFACE_IIC
uint8_t apm2000_basic_init(apm2000_interface_t interface)
basic example init
uint8_t apm2000_basic_read(apm2000_pm_t *pm)
basic example read
uint8_t apm2000_basic_deinit(void)
basic example deinit
uint8_t apm2000_interface_iic_read_address16(uint8_t addr, uint16_t reg, uint8_t *buf, uint16_t len)
interface iic bus read with 16 bits register address
void apm2000_interface_debug_print(const char *const fmt,...)
interface print format data
uint16_t apm2000_interface_uart_read(uint8_t *buf, uint16_t len)
interface uart read
uint8_t apm2000_interface_iic_deinit(void)
interface iic bus deinit
uint8_t apm2000_interface_uart_write(uint8_t *buf, uint16_t len)
interface uart write
uint8_t apm2000_interface_uart_flush(void)
interface uart flush
uint8_t apm2000_interface_iic_init(void)
interface iic bus init
uint8_t apm2000_interface_uart_deinit(void)
interface uart deinit
uint8_t apm2000_interface_iic_write_address16(uint8_t addr, uint16_t reg, uint8_t *buf, uint16_t len)
interface iic bus write with 16 bits register address
void apm2000_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t apm2000_interface_uart_init(void)
interface uart init