LibDriver TPL0501
Loading...
Searching...
No Matches
driver_tpl0501_basic.c
Go to the documentation of this file.
1
36
38
39static tpl0501_handle_t gs_handle;
40
48uint8_t tpl0501_basic_init(void)
49{
50 uint8_t res;
51
52 /* link functions */
59
60 /* tpl0501 init */
61 res = tpl0501_init(&gs_handle);
62 if (res != 0)
63 {
64 tpl0501_interface_debug_print("tpl0501: init failed.\n");
65
66 return 1;
67 }
68
69 return 0;
70}
71
80{
81 /* close tpl0501 */
82 if (tpl0501_deinit(&gs_handle) != 0)
83 {
84 return 1;
85 }
86
87 return 0;
88}
89
100uint8_t tpl0501_basic_write(float percentage, float *wl_ohm, float *hw_ohm)
101{
102 uint8_t res;
103 uint8_t raw;
104
105 /* percentage convert to register */
106 res = tpl0501_percentage_convert_to_register(&gs_handle, percentage, &raw, wl_ohm, hw_ohm);
107 if (res != 0)
108 {
109 return 1;
110 }
111
112 /* write data */
113 res = tpl0501_write(&gs_handle, raw);
114 if (res != 0)
115 {
116 return 1;
117 }
118
119 return 0;
120}
driver tpl0501 basic include file
uint8_t tpl0501_deinit(tpl0501_handle_t *handle)
close the chip
uint8_t tpl0501_percentage_convert_to_register(tpl0501_handle_t *handle, float percentage, uint8_t *reg, float *wl_ohm, float *hw_ohm)
convert the percentage to the register raw data
uint8_t tpl0501_init(tpl0501_handle_t *handle)
initialize the chip
uint8_t tpl0501_write(tpl0501_handle_t *handle, uint8_t raw)
write data
struct tpl0501_handle_s tpl0501_handle_t
tpl0501 handle structure definition
uint8_t tpl0501_basic_deinit(void)
basic example deinit
uint8_t tpl0501_basic_write(float percentage, float *wl_ohm, float *hw_ohm)
basic example write
uint8_t tpl0501_basic_init(void)
basic example init
void tpl0501_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t tpl0501_interface_spi_deinit(void)
interface spi bus deinit
void tpl0501_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t tpl0501_interface_spi_write_cmd(uint8_t *buf, uint16_t len)
interface spi bus write command
uint8_t tpl0501_interface_spi_init(void)
interface spi bus init