CuVoodoo STM32F1 firmware template
busvoodoo_i2c.c
Go to the documentation of this file.
1 /* This program is free software: you can redistribute it and/or modify
2  * it under the terms of the GNU General Public License as published by
3  * the Free Software Foundation, either version 3 of the License, or
4  * (at your option) any later version.
5  *
6  * This program is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  * GNU General Public License for more details.
10  *
11  * You should have received a copy of the GNU General Public License
12  * along with this program. If not, see <http://www.gnu.org/licenses/>.
13  *
14  */
21 /* standard libraries */
22 #include <stdint.h> // standard integer types
23 #include <stdlib.h> // standard utilities
24 #include <string.h> // string utilities
25 
26 /* STM32 (including CM3) libraries */
27 #include <libopencm3/stm32/i2c.h> // I2C library
28 
29 /* own libraries */
30 #include "global.h" // board definitions
31 #include "print.h" // printing utilities
32 #include "menu.h" // menu definitions
33 #include "i2c_master.h" // I2C utilities
34 #include "busvoodoo_global.h" // BusVoodoo definitions
35 #include "busvoodoo_oled.h" // OLED utilities
36 #include "busvoodoo_i2c.h" // own definitions
37 
41 #define BUSVOODOO_I2C I2C2
45 static enum busvoodoo_i2c_setting_t {
46  BUSVOODOO_I2C_SETTING_NONE,
47  BUSVOODOO_I2C_SETTING_SPEED,
48  BUSVOODOO_I2C_SETTING_ADDRESSBITS,
49  BUSVOODOO_I2C_SETTING_PULLUP,
50  BUSVOODOO_I2C_SETTING_DONE,
51 } busvoodoo_i2c_setting = BUSVOODOO_I2C_SETTING_NONE;
53 uint16_t busvoodoo_i2c_speed = 100;
58 
64 static bool busvoodoo_i2c_setup(char** prefix, const char* line)
65 {
66  bool complete = false; // is the setup complete
67  if (NULL==line) { // first call
68  busvoodoo_i2c_setting = BUSVOODOO_I2C_SETTING_NONE; // re-start configuration
69  }
70  switch (busvoodoo_i2c_setting) {
71  case BUSVOODOO_I2C_SETTING_NONE:
73  *prefix = busvoodoo_global_string; // ask for speed
74  busvoodoo_i2c_setting = BUSVOODOO_I2C_SETTING_SPEED;
75  break;
76  case BUSVOODOO_I2C_SETTING_SPEED:
77  if (NULL==line || 0==strlen(line)) { // use default setting
78  busvoodoo_i2c_setting = BUSVOODOO_I2C_SETTING_ADDRESSBITS; // go to next setting
79  } else { // setting provided
80  uint32_t speed = atoi(line); // parse setting
81  if (speed>0 && speed<=400) { // check setting
82  busvoodoo_i2c_speed = speed; // remember setting
83  busvoodoo_i2c_setting = BUSVOODOO_I2C_SETTING_ADDRESSBITS; // go to next setting
84  }
85  }
86  if (BUSVOODOO_I2C_SETTING_ADDRESSBITS==busvoodoo_i2c_setting) { // if next setting
87  snprintf(busvoodoo_global_string, LENGTH(busvoodoo_global_string), "address size in bits (7,10) [%u]", busvoodoo_i2c_addressbits); // prepare next setting
88  *prefix = busvoodoo_global_string; // display next setting
89  }
90  break;
91  case BUSVOODOO_I2C_SETTING_ADDRESSBITS:
92  if (NULL==line || 0==strlen(line)) { // use default setting
93  busvoodoo_i2c_setting = BUSVOODOO_I2C_SETTING_PULLUP; // go to next setting
94  } else { // setting provided
95  uint8_t addressbits = atoi(line); // parse setting
96  if (7==addressbits || 10==addressbits) { // check setting
97  busvoodoo_i2c_addressbits = addressbits; // remember setting
98  busvoodoo_i2c_setting = BUSVOODOO_I2C_SETTING_PULLUP; // go to next setting
99  }
100  }
101  if (BUSVOODOO_I2C_SETTING_PULLUP==busvoodoo_i2c_setting) { // if next setting
102  printf("1) open-drain, with embedded pull-up resistors (2kO)\n");
103  printf("2) open-drain, with external pull-up resistors\n");
104  snprintf(busvoodoo_global_string, LENGTH(busvoodoo_global_string), "drive mode (1,2) [%c]", busvoodoo_i2c_embedded_pullup ? '1' : '2'); // show drive mode
105  *prefix = busvoodoo_global_string; // display next setting
106  }
107  break;
108  case BUSVOODOO_I2C_SETTING_PULLUP:
109  if (NULL==line || 0==strlen(line)) { // use default setting
110  busvoodoo_i2c_setting = BUSVOODOO_I2C_SETTING_DONE; // go to next setting
111  } else if (1==strlen(line)) { // setting provided
112  uint8_t drive = atoi(line); // parse setting
113  if (1==drive || 2==drive) { // check setting
114  busvoodoo_i2c_embedded_pullup = (1==drive); // remember setting
115  busvoodoo_i2c_setting = BUSVOODOO_I2C_SETTING_DONE; // go to next setting
116  }
117  }
118  if (BUSVOODOO_I2C_SETTING_DONE==busvoodoo_i2c_setting) { // we have all settings, configure I2C
121  busvoodoo_embedded_pullup(true); // set pull-up
122  printf("use LV to set pull-up voltage\n");
123  }
124  busvoodoo_led_blue_off(); // disable blue LED because there is no activity
125  busvoodoo_i2c_setting = BUSVOODOO_I2C_SETTING_NONE; // restart settings next time
126  *prefix = "I2C"; // display mode
127  busvoodoo_oled_text_left(*prefix); // set mode title on OLED display
128  const char* pinout_io[10] = {"GND", "5V", "3V3", "LV", "SDA", "SCL", NULL, NULL}; // HiZ mode pinout
129  for (uint8_t i=0; i<LENGTH(pinout_io) && i<LENGTH(busvoodoo_global_pinout_io); i++) {
130  busvoodoo_global_pinout_io[i] = pinout_io[i]; // set pin names
131  }
132  if (busvoodoo_full) {
133  const char* pinout_rscan[5] = {"HV", NULL, NULL, NULL, NULL}; // HiZ mode RS/CAN pinout
134  for (uint8_t i=0; i<LENGTH(pinout_rscan) && i<LENGTH(busvoodoo_global_pinout_rscan); i++) {
135  busvoodoo_global_pinout_rscan[i] = pinout_rscan[i]; // set pin names
136  }
137  }
138  busvoodoo_oled_text_pinout(pinout_io, true); // set pinout on display
139  busvoodoo_oled_update(); // update display to show text and pinout
140  complete = true; // configuration is complete
141  }
142  break;
143  case BUSVOODOO_I2C_SETTING_DONE: // this case is already handled before
144  default: // unknown case
145  busvoodoo_i2c_setting = BUSVOODOO_I2C_SETTING_NONE; // restart settings next time
146  complete = false; // restart setting
147  break;
148  }
149  return complete;
150 }
151 
154 static void busvoodoo_i2c_exit(void)
155 {
156  i2c_master_release(BUSVOODOO_I2C); // release I2C peripheral
157  busvoodoo_embedded_pullup(false); // disable embedded pull-ups
158 }
159 
161 static void busvoodoo_i2c_read(void)
162 {
163  printf("read: ");
164  busvoodoo_led_blue_pulse(BUSVOODOO_LED_PULSE); // pulse blue LED to show we read data
165  uint8_t data; // to store the data read
166  switch (i2c_master_read(BUSVOODOO_I2C, &data, 1)) {
167  case I2C_MASTER_RC_NONE: // all went fine
168  printf("0x%02x", data); // show data
169  break;
171  printf("slave not selected");
172  break;
174  printf("slave not ready");
175  break;
177  printf("not in receive mode");
178  break;
180  printf("error detected on bus (reset I2C peripheral to correct)");
181  break;
182  default:
183  printf("error");
184  }
185  printf("\n");
186 }
187 
191 static void busvoodoo_i2c_write(uint8_t data)
192 {
193  printf("write 0x%02x: ", data);
194  busvoodoo_led_blue_pulse(BUSVOODOO_LED_PULSE); // pulse blue LED to show we send data
195  switch (i2c_master_write(BUSVOODOO_I2C, &data, 1)) {
196  case I2C_MASTER_RC_NONE: // all went fine
197  printf("ack");
198  break;
199  case I2C_MASTER_RC_NAK:
200  printf("nack");
201  break;
203  printf("slave not selected");
204  break;
206  printf("slave not ready");
207  break;
209  printf("not in transmit mode");
210  break;
212  printf("error detected on bus (reset I2C peripheral to correct)");
213  break;
214  default:
215  printf("error");
216  }
217  printf("\n");
218 }
219 
224 static void busvoodoo_i2c_select(uint16_t slave, bool write)
225 {
226  printf("select slave ");
227  if (10==busvoodoo_i2c_addressbits) {
228  printf("0x%03x", slave);
229  } else {
230  printf("0x%02x", slave);
231  }
232  printf(" to %s: ", write ? "write" : "read");
233  busvoodoo_led_blue_pulse(BUSVOODOO_LED_PULSE); // pulse blue LED to show we send the slave address
235  case I2C_MASTER_RC_NONE: // all went fine
236  printf("selected");
237  break;
238  case I2C_MASTER_RC_NAK:
239  printf("no such slave");
240  break;
242  printf("can't become master");
243  break;
245  printf("not in receive mode");
246  break;
248  printf("not in transmit mode");
249  break;
251  printf("error detected on bus (reset I2C peripheral to correct)");
252  break;
253  default:
254  printf("error");
255  }
256  printf("\n");
257 }
258 
265 static bool busvoodoo_i2c_action(const char* action, uint32_t repetition, bool perform)
266 {
267  uint32_t length = strlen(action); // remember length since it will be used a number of times
268  if (NULL==action || 0==length) { // there is nothing to do
269  return true;
270  }
271 
272  if (1==length && 'r'==action[0]) { // read data
273  if (!perform) {
274  return true;
275  }
276  for (uint32_t i=0; i<repetition; i++) {
277  busvoodoo_i2c_read(); // read from I2C
278  }
279  } else if (1==length && '['==action[0]) { // select slave
280  if (!perform) {
281  return true;
282  }
283  printf("send start condition: ");
284  for (uint32_t i=0; i<repetition; i++) {
285  busvoodoo_led_blue_pulse(BUSVOODOO_LED_PULSE); // pulse blue LED to show we send start condition
286  printf("%s ", I2C_MASTER_RC_NONE==i2c_master_start(BUSVOODOO_I2C) ? "sent" : "error");
287  }
288  printf("\n");
289  } else if (1==length && ']'==action[0]) { // deselect slave
290  if (!perform) {
291  return true;
292  }
293  printf("send stop condition: ");
294  for (uint32_t i=0; i<repetition; i++) {
295  busvoodoo_led_blue_pulse(BUSVOODOO_LED_PULSE); // pulse blue LED to show we send stop condition
296  printf("%s ", I2C_MASTER_RC_NONE==i2c_master_stop(BUSVOODOO_I2C) ? "sent" : "error");
297  }
298  printf("\n");
299  } else if (1==length && 'u'==action[0]) { // sleep us
300  if (!perform) {
301  return true;
302  }
303  printf("wait for %u us\n", repetition);
304  sleep_us(repetition); // sleep
305  } else if (1==length && 'm'==action[0]) { // sleep ms
306  if (!perform) {
307  return true;
308  }
309  printf("wait for %u ms\n", repetition);
310  sleep_ms(repetition); // sleep
311  } else if ('0'==action[0]) { // send digit
312  if (1==length) { // just send 0
313  if (!perform) {
314  return true;
315  }
316  for (uint32_t i=0; i<repetition; i++) {
317  busvoodoo_i2c_write(0); // write to I2C
318  }
319  } else if ('x'==action[1] || 'b'==action[1]) { // send hex/binary
320  return busvoodoo_i2c_action(action+1, repetition, perform); // just retry without leading 0
321  } else if (action[1]>='0' && action[1]<='9') { // send decimal
322  return busvoodoo_i2c_action(action+1, repetition, perform); // just retry without leading 0
323  } else if ('r'==action[1] && 2==length) { // select slave to read
324  busvoodoo_i2c_select(0, false); // select slave 0 to read
325  } else if ('w'==action[1] && 2==length) { // select slave to write
326  busvoodoo_i2c_select(0, true); // select slave 0 to write
327  } else { // malformed action
328  return false;
329  }
330  } else if ('x'==action[0] && length>1) { // send hexadecimal value
331  for (uint32_t i=1; i<length; i++) { // check string
332  if (!((action[i]>='0' && action[i]<='9') || (action[i]>='a' && action[i]<='f') || (action[i]>='A' && action[i]<='F') || ('r'==action[i] && i==length-1) || ('w'==action[i] && i==length-1))) { // check for hexadecimal character or r/w flag
333  return false; // not an hexadecimal string
334  }
335  }
336  if (!perform) {
337  return true;
338  }
339  uint32_t value = strtol(&action[1], NULL, 16); // get hex value
340  for (uint32_t i=0; i<repetition; i++) {
341  if ('r'==action[length-1]) {
342  busvoodoo_i2c_select(value, false); // select slave to read
343  } else if ('w'==action[length-1]) {
344  busvoodoo_i2c_select(value, true); // select slave to write
345  } else {
346  busvoodoo_i2c_write(value); // write to I2C
347  }
348  }
349  } else if ('b'==action[0] && length>1) { // send binary value
350  for (uint32_t i=1; i<length; i++) { // check string
351  if (!('0'==action[i] || '1'==action[i] || ('r'==action[i] && i==length-1) || ('w'==action[i] && i==length-1))) { // check for binary character or r/w flag
352  return false; // not a binary string
353  }
354  }
355  if (!perform) {
356  return true;
357  }
358  uint32_t value = strtol(&action[1], NULL, 2); // get binary value
359  for (uint32_t i=0; i<repetition; i++) {
360  if ('r'==action[length-1]) {
361  busvoodoo_i2c_select(value, false); // select slave to read
362  } else if ('w'==action[length-1]) {
363  busvoodoo_i2c_select(value, true); // select slave to write
364  } else {
365  busvoodoo_i2c_write(value); // write to I2C
366  }
367  }
368  } else if (action[0]>='1' && action[0]<='9') { // send decimal value
369  for (uint32_t i=1; i<length; i++) { // check string
370  if (!((action[i]>='0' && action[i]<='9') || ('w'==action[i] && i==length-1))) { // check for decimal character or r/w flag
371  return false; // not a decimal string
372  }
373  }
374  if (!perform) {
375  return true;
376  }
377  uint32_t value = strtol(&action[0], NULL, 10); // get decimal value
378  for (uint32_t i=0; i<repetition; i++) {
379  if ('r'==action[length-1]) {
380  busvoodoo_i2c_select(value, false); // select slave to read
381  } else if ('w'==action[length-1]) {
382  busvoodoo_i2c_select(value, true); // select slave to write
383  } else {
384  busvoodoo_i2c_write(value); // write to I2C
385  }
386  }
387  } else if (length>=2 && ('"'==action[0] || '\''==action[0]) && (action[length-1]==action[0])) { // send ASCII character
388  if (!perform) {
389  return true;
390  }
391  for (uint32_t r=0; r<repetition; r++) {
392  for (uint32_t i=1; i<length-1; i++) { // go through string
393  busvoodoo_i2c_write(action[i]); // write to I2C
394  }
395  }
396  } else { // malformed action
397  return false;
398  }
399  return true; // all went well
400 }
401 
402 // command handlers
403 
407 static void busvoodoo_i2c_command_reset(void* argument)
408 {
409  (void)argument; // we won't use the argument
410  i2c_master_reset(BUSVOODOO_I2C); // reset the I2C peripheral since it might be stuck
412  printf("I2C peripheral reset\n");
413 }
414 
415 
419 static void busvoodoo_i2c_command_actions(void* argument)
420 {
421  if (NULL==argument || 0==strlen(argument)) {
422  printf("available actions (separated by space or ,):\n");
423  printf("[/]\tsend start/stop conditions\n");
424  printf("0x0r\tselect slave with I2C address to read\n");
425  printf("0x0w\tselect slave with I2C address to write\n");
426  printf("0\twrite decimal value\n");
427  printf("0x0\twrite hexadecimal value\n");
428  printf("0b0\twrite binary value\n");
429  printf("\"a\"/'a'\twrite ASCII characters\n");
430  printf("r\tread value\n");
431  printf("u/m\twait 1 us/ms\n");
432  printf(":n\trepeat action n times\n");
433  return;
434  }
435  // copy argument since it will be modified
436  char* copy = calloc(strlen(argument)+1, sizeof(char));
437  if (!copy) {
438  while (true);
439  }
440  strncpy(copy, argument, strlen(argument)+1);
441  // verify and perform actions
442  if (!busvoodoo_global_actions(copy, false, &busvoodoo_i2c_action)) { // verify actions
443  printf("malformed action(s)\n");
444  } else { // action are ok
445  busvoodoo_global_actions(argument, true, &busvoodoo_i2c_action); // perform action
446  }
447  free(copy); // release memory
448 }
449 
453 static void busvoodoo_i2c_command_scan(void* argument)
454 {
455  (void)argument; // we won't use the argument
456  if (!i2c_master_check_signals(BUSVOODOO_I2C)) { // ensure SCL and SDA are high
457  printf("SCL or/and SDA are low. The signals need to be pulled up\n");
459  printf("set pull-up voltage with LV\n");
460  }
461  busvoodoo_leds_blink(0.5, 0.5); // show error on LEDs
462  return; // stop here
463  } else {
464  busvoodoo_led_blue_off(); // clear blinking
465  }
466  printf("scanning for I2C slaves\n");
467  int16_t i2c_slaves = 0; // number of slaves found
468  // check for I2C slaves by going through the address space
469  printf("I2C slaves found: ");
470  for (uint16_t address=0; address < (1<<busvoodoo_i2c_addressbits); address++) {
471  busvoodoo_led_blue_pulse(BUSVOODOO_LED_PULSE); // pulse blue LED to show transmission
472  switch (i2c_master_select_slave(BUSVOODOO_I2C, address, 10==busvoodoo_i2c_addressbits, false)) { // try to select slave (includes start condition)
473  case I2C_MASTER_RC_NONE: // slave found
474  busvoodoo_led_blue_pulse(BUSVOODOO_LED_PULSE); // pulse blue LED to show we found a slave
475  printf((busvoodoo_i2c_addressbits>7) ? "0x%03x " : "0x%02x ", address); // display address
476  i2c_slaves++; // increase slave count
477  break;
478  case I2C_MASTER_RC_START_STOP_IN_PROGESS: // I2C peripheral error
479  printf("start condition failed\n"); // show error to user
480  i2c_slaves = -2; // remember error
481  break; // stop scanning
482  case I2C_MASTER_RC_NOT_MASTER: // start condition failed
483  i2c_master_reset(BUSVOODOO_I2C); // reset the I2C peripheral since it might be stuck
484  printf("start condition failed\n"); // show error to user
485  i2c_slaves = -1; // remember error
486  break; // stop scanning
487  case I2C_MASTER_RC_NAK: // slave did not respond
488  break; // nothing to do
490  printf("error detected on bus\n");
491  i2c_slaves = -2; // remember error
492  break;
493  default: // unexpected error
494  printf("error occurred\n");
495  i2c_slaves = -1; // remember error
496  break;
497  }
498  if (i2c_slaves<0) { // error happened
499  busvoodoo_leds_blink(0.5, 0.5); // show error on LEDs
500  if (-1==i2c_slaves) { // just end communication
501  i2c_master_stop(BUSVOODOO_I2C); // send stop condition
502  } else if (-2==i2c_slaves) { // reset peripheral
504  }
505  break; // stop scan
506  } else {
507  if (I2C_MASTER_RC_NONE!=i2c_master_stop(BUSVOODOO_I2C)) { // stop stop condition
508  i2c_master_reset(BUSVOODOO_I2C); // reset the I2C peripheral since it might be stuck
509  printf("stop condition failed\n"); // show error to user
510  busvoodoo_leds_blink(0.5, 0.5); // show error on LEDs
511  i2c_slaves = -1; // remember error
512  break;
513  }
514  }
515  }
516  printf("\n");
517  if (i2c_slaves>=0) {
518  printf("%u slave(s) found\n", i2c_slaves); // show summary
519  }
520 }
521 
523 static const struct menu_command_t busvoodoo_i2c_commands[] = {
524  {
525  .shortcut = 'r',
526  .name = "reset_i2c",
527  .command_description = "reset I2C peripheral",
528  .argument = MENU_ARGUMENT_NONE,
529  .argument_description = NULL,
530  .command_handler = &busvoodoo_i2c_command_reset,
531  },
532  {
533  .shortcut = 'a',
534  .name = "action",
535  .command_description = "perform protocol actions",
536  .argument = MENU_ARGUMENT_STRING,
537  .argument_description = "[actions]",
538  .command_handler = &busvoodoo_i2c_command_actions,
539  },
540  {
541  .shortcut = 's',
542  .name = "scan",
543  .command_description = "scan for slave devices",
544  .argument = MENU_ARGUMENT_NONE,
545  .argument_description = NULL,
546  .command_handler = &busvoodoo_i2c_command_scan,
547  },
548 };
549 
551  .name = "i2c",
552  .description = "Inter-Integrated Circuit",
553  .full_only = false,
554  .setup = &busvoodoo_i2c_setup,
555  .commands = busvoodoo_i2c_commands,
556  .commands_nb = LENGTH(busvoodoo_i2c_commands),
557  .exit = &busvoodoo_i2c_exit,
558 };
library to communicate using I2C as master (API)
command menu entry
Definition: menu.h:31
enum i2c_master_rc i2c_master_stop(uint32_t i2c)
sent stop condition
Definition: i2c_master.c:464
#define BUSVOODOO_LED_PULSE
recommended duration in ms for pulsing LEDs to show activity
static void busvoodoo_i2c_command_reset(void *argument)
command to reset I2C peripheral
BusVoodoo global definitions and methods (API)
enum i2c_master_rc i2c_master_select_slave(uint32_t i2c, uint16_t slave, bool address_10bit, bool write)
select I2C slave device
Definition: i2c_master.c:311
static void busvoodoo_i2c_write(uint8_t data)
write to I2C
not in receive mode
Definition: i2c_master.h:29
void busvoodoo_oled_text_pinout(const char *pins[10], bool io_connector)
draw pin names on bottom (blue) part in display buffer
const char * name
name of the mode (i.e.
enum i2c_master_rc i2c_master_read(uint32_t i2c, uint8_t *data, size_t data_size)
read data over I2C
Definition: i2c_master.c:389
void busvoodoo_led_blue_pulse(uint32_t ms)
pulse blue LED for short duration
void i2c_master_reset(uint32_t i2c)
reset I2C peripheral, fixing any locked state
Definition: i2c_master.c:254
an error on the I2C bus occurred
Definition: i2c_master.h:32
enum i2c_master_rc i2c_master_start(uint32_t i2c)
send start condition
Definition: i2c_master.c:284
void busvoodoo_oled_update(void)
update OLED display RAM with current display buffer
uint16_t busvoodoo_i2c_speed
I2C speed (in kHz)
Definition: busvoodoo_i2c.c:53
const char * busvoodoo_global_pinout_rscan[5]
RS/CAN connector pinout.
global definitions and methods (API)
static void busvoodoo_i2c_exit(void)
exit I2C mode
void sleep_us(uint32_t duration)
go to sleep for some microseconds
Definition: global.c:102
not in master mode
Definition: i2c_master.h:27
bool busvoodoo_full
is the BusVoodoo board fully populated (with HV voltage regulator, RS-232, RS-485, CAN transceiver on the back side)
static void busvoodoo_i2c_select(uint16_t slave, bool write)
select I2C slave
void busvoodoo_led_blue_off(void)
switch off blue LED
enum i2c_master_rc i2c_master_write(uint32_t i2c, const uint8_t *data, size_t data_size)
write data over I2C
Definition: i2c_master.c:427
a start or stop condition is already in progress
Definition: i2c_master.h:26
#define BUSVOODOO_I2C
I2C peripheral.
Definition: busvoodoo_i2c.c:41
bool busvoodoo_i2c_embedded_pullup
if embedded or external pull-up resistors are use
Definition: busvoodoo_i2c.c:57
void i2c_master_setup(uint32_t i2c, uint16_t frequency)
setup I2C peripheral
Definition: i2c_master.c:173
char shortcut
short command code (0 if not available)
Definition: menu.h:32
void busvoodoo_leds_blink(double period, double duty)
set LED blinking pattern
void i2c_master_release(uint32_t i2c)
release I2C peripheral
Definition: i2c_master.c:211
const char * busvoodoo_global_pinout_io[10]
I/O connector pinout.
static bool busvoodoo_i2c_setup(char **prefix, const char *line)
setup I2C mode
Definition: busvoodoo_i2c.c:64
char busvoodoo_global_string[64]
shared string buffer, i.e.
static const struct menu_command_t busvoodoo_i2c_commands[]
I2C menu commands.
bool busvoodoo_global_actions(char *actions, bool perform, bool(*action_handler)(const char *action, uint32_t repetition, bool perform))
parse and perform actions
static bool busvoodoo_i2c_action(const char *action, uint32_t repetition, bool perform)
perform I2C action
void sleep_ms(uint32_t duration)
go to sleep for some milliseconds
Definition: global.c:117
slave is not read (previous operations has been nacked)
Definition: i2c_master.h:30
void busvoodoo_oled_text_left(char *text)
draw mode text on top (yellow) left side in display buffer
float busvoodoo_embedded_pullup(bool on)
enable embedded pull-up resistors
static void busvoodoo_i2c_read(void)
read from I2C
#define LENGTH(x)
get the length of an array
Definition: global.h:26
bool i2c_master_check_signals(uint32_t i2c)
check if SDA and SCL signals are high
Definition: i2c_master.c:225
const struct busvoodoo_mode_t busvoodoo_i2c_mode
I2C mode interface definition.
not in transmit mode
Definition: i2c_master.h:28
library to show BusVoodoo mode information on SSD1306 OLED display: name, activity, pinout (API)
static enum busvoodoo_i2c_setting_t busvoodoo_i2c_setting
current mode setup stage
BusVoodoo mode interface.
static void busvoodoo_i2c_command_actions(void *argument)
command to perform actions
uint8_t busvoodoo_i2c_addressbits
I2C address bits (7 or 10)
Definition: busvoodoo_i2c.c:55
BusVoodoo I²C mode (API)
static void busvoodoo_i2c_command_scan(void *argument)
command to scan for slave devices
not acknowledge received
Definition: i2c_master.h:31