LibDriver TM1638  1.0.0
TM1638 full-featured driver
driver_tm1638_basic.c
Go to the documentation of this file.
1 
37 #include "driver_tm1638_basic.h"
38 
39 static tm1638_handle_t gs_handle;
48 uint8_t tm1638_basic_init(void)
49 {
50  uint8_t res;
51 
52  /* link interface function */
60 
61  /* tm1638 init */
62  res = tm1638_init(&gs_handle);
63  if (res != 0)
64  {
65  tm1638_interface_debug_print("tm1638: init failed.\n");
66 
67  return 1;
68  }
69 
70  /* set default address mode */
72  if (res != 0)
73  {
74  tm1638_interface_debug_print("tm1638: set address mode failed.\n");
75  (void)tm1638_deinit(&gs_handle);
76 
77  return 1;
78  }
79 
80  /* disable test mode */
81  res = tm1638_set_test_mode(&gs_handle, TM1638_BOOL_FALSE);
82  if (res != 0)
83  {
84  tm1638_interface_debug_print("tm1638: set test mode failed.\n");
85  (void)tm1638_deinit(&gs_handle);
86 
87  return 1;
88  }
89 
90  /* set default pulse width */
92  if (res != 0)
93  {
94  tm1638_interface_debug_print("tm1638: set pulse width failed.\n");
95  (void)tm1638_deinit(&gs_handle);
96 
97  return 1;
98  }
99 
100  /* clear segment */
101  res = tm1638_clear_segment(&gs_handle);
102  if (res != 0)
103  {
104  tm1638_interface_debug_print("tm1638: clear segment failed.\n");
105  (void)tm1638_deinit(&gs_handle);
106 
107  return 1;
108  }
109 
110  /* enable display */
111  res = tm1638_set_display(&gs_handle, TM1638_BOOL_TRUE);
112  if (res != 0)
113  {
114  tm1638_interface_debug_print("tm1638: set display failed.\n");
115  (void)tm1638_deinit(&gs_handle);
116 
117  return 1;
118  }
119 
120  return 0;
121 }
122 
133 uint8_t tm1638_basic_write(uint8_t addr, uint16_t *data, uint8_t len)
134 {
135  uint8_t res;
136 
137  /* write segment */
138  res = tm1638_write_segment(&gs_handle, addr, data, len);
139  if (res != 0)
140  {
141  return 1;
142  }
143 
144  return 0;
145 }
146 
154 uint8_t tm1638_basic_clear(void)
155 {
156  uint8_t res;
157 
158  /* clear segment */
159  res = tm1638_clear_segment(&gs_handle);
160  if (res != 0)
161  {
162  return 1;
163  }
164 
165  return 0;
166 }
167 
176 {
177  uint8_t res;
178 
179  /* display on */
180  res = tm1638_set_display(&gs_handle, TM1638_BOOL_TRUE);
181  if (res != 0)
182  {
183  return 1;
184  }
185 
186  return 0;
187 }
188 
197 {
198  uint8_t res;
199 
200  /* display off */
201  res = tm1638_set_display(&gs_handle, TM1638_BOOL_FALSE);
202  if (res != 0)
203  {
204  return 1;
205  }
206 
207  return 0;
208 }
209 
218 uint8_t tm1638_basic_read(uint8_t segk[4])
219 {
220  uint8_t res;
221 
222  /* read segment */
223  res = tm1638_read_segment(&gs_handle, segk);
224  if (res != 0)
225  {
226  return 1;
227  }
228 
229  return 0;
230 }
231 
239 uint8_t tm1638_basic_deinit(void)
240 {
241  uint8_t res;
242 
243  /* deinit tm1638 */
244  res = tm1638_deinit(&gs_handle);
245  if (res != 0)
246  {
247  return 1;
248  }
249 
250  return 0;
251 }
driver tm1638 basic header file
uint8_t tm1638_write_segment(tm1638_handle_t *handle, uint8_t addr, uint16_t *data, uint8_t len)
write segment
uint8_t tm1638_set_address_mode(tm1638_handle_t *handle, tm1638_address_mode_t mode)
set address mode
uint8_t tm1638_set_pulse_width(tm1638_handle_t *handle, tm1638_pulse_width_t width)
set pulse width
uint8_t tm1638_deinit(tm1638_handle_t *handle)
close the chip
uint8_t tm1638_clear_segment(tm1638_handle_t *handle)
clear segment
uint8_t tm1638_init(tm1638_handle_t *handle)
initialize the chip
uint8_t tm1638_read_segment(tm1638_handle_t *handle, uint8_t segk[4])
read segment
uint8_t tm1638_set_display(tm1638_handle_t *handle, tm1638_bool_t enable)
enable or disable display
uint8_t tm1638_set_test_mode(tm1638_handle_t *handle, tm1638_bool_t enable)
enable or disable test mode
@ TM1638_BOOL_FALSE
Definition: driver_tm1638.h:73
@ TM1638_BOOL_TRUE
Definition: driver_tm1638.h:74
uint8_t tm1638_basic_deinit(void)
basic example deinit
uint8_t tm1638_basic_write(uint8_t addr, uint16_t *data, uint8_t len)
basic example write
uint8_t tm1638_basic_display_on(void)
basic example display on
uint8_t tm1638_basic_read(uint8_t segk[4])
basic example read
uint8_t tm1638_basic_display_off(void)
basic example display off
#define TM1638_BASIC_DEFAULT_PULSE_WIDTH
uint8_t tm1638_basic_clear(void)
basic example clear
uint8_t tm1638_basic_init(void)
basic example init
#define TM1638_BASIC_DEFAULT_ADDRESS_MODE
tm1638 basic example default definition
uint8_t tm1638_interface_spi_read(uint8_t addr, uint8_t *buf, uint16_t len)
interface spi read
void tm1638_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t tm1638_interface_spi_deinit(void)
interface spi deinit
uint8_t tm1638_interface_spi_init(void)
interface spi init
uint8_t tm1638_interface_spi_write(uint8_t addr, uint8_t *buf, uint16_t len)
interface spi write
void tm1638_interface_debug_print(const char *const fmt,...)
interface print format data
tm1638 handle structure definition