busvoodoo_i2c.c
Go to the documentation of this file.
/* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* standard libraries */
#include <stdint.h> // standard integer types
#include <stdlib.h> // standard utilities
#include <string.h> // string utilities
/* STM32 (including CM3) libraries */
#include <libopencm3/stm32/i2c.h> // I2C library
/* own libraries */
#include "global.h" // board definitions
#include "print.h" // printing utilities
#include "menu.h" // menu definitions
#include "i2c_master.h" // I2C utilities
#include "busvoodoo_global.h" // BusVoodoo definitions
#include "busvoodoo_oled.h" // OLED utilities
#include "busvoodoo_i2c.h" // own definitions
#define BUSVOODOO_I2C I2C2
static enum busvoodoo_i2c_setting_t {
BUSVOODOO_I2C_SETTING_NONE,
BUSVOODOO_I2C_SETTING_SPEED,
BUSVOODOO_I2C_SETTING_ADDRESSBITS,
BUSVOODOO_I2C_SETTING_PULLUP,
BUSVOODOO_I2C_SETTING_DONE,
} busvoodoo_i2c_setting = BUSVOODOO_I2C_SETTING_NONE;
uint16_t busvoodoo_i2c_speed = 100;
uint8_t busvoodoo_i2c_addressbits = 7;
bool busvoodoo_i2c_embedded_pullup = true;
static bool busvoodoo_i2c_setup(char** prefix, const char* line)
{
bool complete = false; // is the setup complete
if (NULL==line) { // first call
busvoodoo_i2c_setting = BUSVOODOO_I2C_SETTING_NONE; // re-start configuration
}
switch (busvoodoo_i2c_setting) {
case BUSVOODOO_I2C_SETTING_NONE:
snprintf(busvoodoo_global_string, LENGTH(busvoodoo_global_string), "speed in kHz (1-400) [%u]", busvoodoo_i2c_speed);
*prefix = busvoodoo_global_string; // ask for speed
busvoodoo_i2c_setting = BUSVOODOO_I2C_SETTING_SPEED;
break;
case BUSVOODOO_I2C_SETTING_SPEED:
if (NULL==line || 0==strlen(line)) { // use default setting
busvoodoo_i2c_setting = BUSVOODOO_I2C_SETTING_ADDRESSBITS; // go to next setting
} else { // setting provided
uint32_t speed = atoi(line); // parse setting
if (speed>0 && speed<=400) { // check setting
busvoodoo_i2c_speed = speed; // remember setting
busvoodoo_i2c_setting = BUSVOODOO_I2C_SETTING_ADDRESSBITS; // go to next setting
}
}
if (BUSVOODOO_I2C_SETTING_ADDRESSBITS==busvoodoo_i2c_setting) { // if next setting
snprintf(busvoodoo_global_string, LENGTH(busvoodoo_global_string), "address size in bits (7,10) [%u]", busvoodoo_i2c_addressbits); // prepare next setting
*prefix = busvoodoo_global_string; // display next setting
}
break;
case BUSVOODOO_I2C_SETTING_ADDRESSBITS:
if (NULL==line || 0==strlen(line)) { // use default setting
busvoodoo_i2c_setting = BUSVOODOO_I2C_SETTING_PULLUP; // go to next setting
} else { // setting provided
uint8_t addressbits = atoi(line); // parse setting
if (7==addressbits || 10==addressbits) { // check setting
busvoodoo_i2c_addressbits = addressbits; // remember setting
busvoodoo_i2c_setting = BUSVOODOO_I2C_SETTING_PULLUP; // go to next setting
}
}
if (BUSVOODOO_I2C_SETTING_PULLUP==busvoodoo_i2c_setting) { // if next setting
printf("1) open-drain, with embedded pull-up resistors (2kO)\n");
printf("2) open-drain, with external pull-up resistors\n");
snprintf(busvoodoo_global_string, LENGTH(busvoodoo_global_string), "drive mode (1,2) [%c]", busvoodoo_i2c_embedded_pullup ? '1' : '2'); // show drive mode
*prefix = busvoodoo_global_string; // display next setting
}
break;
case BUSVOODOO_I2C_SETTING_PULLUP:
if (NULL==line || 0==strlen(line)) { // use default setting
busvoodoo_i2c_setting = BUSVOODOO_I2C_SETTING_DONE; // go to next setting
} else if (1==strlen(line)) { // setting provided
uint8_t drive = atoi(line); // parse setting
if (1==drive || 2==drive) { // check setting
busvoodoo_i2c_embedded_pullup = (1==drive); // remember setting
busvoodoo_i2c_setting = BUSVOODOO_I2C_SETTING_DONE; // go to next setting
}
}
if (BUSVOODOO_I2C_SETTING_DONE==busvoodoo_i2c_setting) { // we have all settings, configure I2C
i2c_master_setup(BUSVOODOO_I2C, busvoodoo_i2c_speed); // setup I2C
if (busvoodoo_i2c_embedded_pullup) {
busvoodoo_embedded_pullup(true); // set pull-up
printf("use LV to set pull-up voltage\n");
}
busvoodoo_led_blue_off(); // disable blue LED because there is no activity
busvoodoo_i2c_setting = BUSVOODOO_I2C_SETTING_NONE; // restart settings next time
*prefix = "I2C"; // display mode
busvoodoo_oled_text_left(*prefix); // set mode title on OLED display
const char* pinout_io[10] = {"GND", "5V", "3V3", "LV", "SDA", "SCL", NULL, NULL}; // HiZ mode pinout
for (uint8_t i=0; i<LENGTH(pinout_io) && i<LENGTH(busvoodoo_global_pinout_io); i++) {
busvoodoo_global_pinout_io[i] = pinout_io[i]; // set pin names
}
if (busvoodoo_full) {
const char* pinout_rscan[5] = {"HV", NULL, NULL, NULL, NULL}; // HiZ mode RS/CAN pinout
for (uint8_t i=0; i<LENGTH(pinout_rscan) && i<LENGTH(busvoodoo_global_pinout_rscan); i++) {
busvoodoo_global_pinout_rscan[i] = pinout_rscan[i]; // set pin names
}
}
busvoodoo_oled_text_pinout(pinout_io, true); // set pinout on display
busvoodoo_oled_update(); // update display to show text and pinout
complete = true; // configuration is complete
}
break;
case BUSVOODOO_I2C_SETTING_DONE: // this case is already handled before
default: // unknown case
busvoodoo_i2c_setting = BUSVOODOO_I2C_SETTING_NONE; // restart settings next time
complete = false; // restart setting
break;
}
return complete;
}
static void busvoodoo_i2c_exit(void)
{
i2c_master_release(BUSVOODOO_I2C); // release I2C peripheral
busvoodoo_embedded_pullup(false); // disable embedded pull-ups
}
static void busvoodoo_i2c_read(void)
{
printf("read: ");
busvoodoo_led_blue_pulse(BUSVOODOO_LED_PULSE); // pulse blue LED to show we read data
uint8_t data; // to store the data read
switch (i2c_master_read(BUSVOODOO_I2C, &data, 1)) {
case I2C_MASTER_RC_NONE: // all went fine
printf("0x%02x", data); // show data
break;
case I2C_MASTER_RC_NOT_MASTER:
printf("slave not selected");
break;
case I2C_MASTER_RC_NOT_READY:
printf("slave not ready");
break;
case I2C_MASTER_RC_NOT_RECEIVE:
printf("not in receive mode");
break;
case I2C_MASTER_RC_BUS_ERROR:
printf("error detected on bus (reset I2C peripheral to correct)");
break;
default:
printf("error");
}
printf("\n");
}
static void busvoodoo_i2c_write(uint8_t data)
{
printf("write 0x%02x: ", data);
busvoodoo_led_blue_pulse(BUSVOODOO_LED_PULSE); // pulse blue LED to show we send data
switch (i2c_master_write(BUSVOODOO_I2C, &data, 1)) {
case I2C_MASTER_RC_NONE: // all went fine
printf("ack");
break;
case I2C_MASTER_RC_NAK:
printf("nack");
break;
case I2C_MASTER_RC_NOT_MASTER:
printf("slave not selected");
break;
case I2C_MASTER_RC_NOT_READY:
printf("slave not ready");
break;
case I2C_MASTER_RC_NOT_TRANSMIT:
printf("not in transmit mode");
break;
case I2C_MASTER_RC_BUS_ERROR:
printf("error detected on bus (reset I2C peripheral to correct)");
break;
default:
printf("error");
}
printf("\n");
}
static void busvoodoo_i2c_select(uint16_t slave, bool write)
{
printf("select slave ");
if (10==busvoodoo_i2c_addressbits) {
printf("0x%03x", slave);
} else {
printf("0x%02x", slave);
}
printf(" to %s: ", write ? "write" : "read");
busvoodoo_led_blue_pulse(BUSVOODOO_LED_PULSE); // pulse blue LED to show we send the slave address
switch (i2c_master_select_slave(BUSVOODOO_I2C, slave, 10==busvoodoo_i2c_addressbits, write)) {
case I2C_MASTER_RC_NONE: // all went fine
printf("selected");
break;
case I2C_MASTER_RC_NAK:
printf("no such slave");
break;
case I2C_MASTER_RC_NOT_MASTER:
printf("can't become master");
break;
case I2C_MASTER_RC_NOT_RECEIVE:
printf("not in receive mode");
break;
case I2C_MASTER_RC_NOT_TRANSMIT:
printf("not in transmit mode");
break;
case I2C_MASTER_RC_BUS_ERROR:
printf("error detected on bus (reset I2C peripheral to correct)");
break;
default:
printf("error");
}
printf("\n");
}
static bool busvoodoo_i2c_action(const char* action, uint32_t repetition, bool perform)
{
uint32_t length = strlen(action); // remember length since it will be used a number of times
if (NULL==action || 0==length) { // there is nothing to do
return true;
}
if (1==length && 'r'==action[0]) { // read data
if (!perform) {
return true;
}
for (uint32_t i=0; i<repetition; i++) {
busvoodoo_i2c_read(); // read from I2C
}
} else if (1==length && '['==action[0]) { // select slave
if (!perform) {
return true;
}
printf("send start condition: ");
for (uint32_t i=0; i<repetition; i++) {
busvoodoo_led_blue_pulse(BUSVOODOO_LED_PULSE); // pulse blue LED to show we send start condition
printf("%s ", I2C_MASTER_RC_NONE==i2c_master_start(BUSVOODOO_I2C) ? "sent" : "error");
}
printf("\n");
} else if (1==length && ']'==action[0]) { // deselect slave
if (!perform) {
return true;
}
printf("send stop condition: ");
for (uint32_t i=0; i<repetition; i++) {
busvoodoo_led_blue_pulse(BUSVOODOO_LED_PULSE); // pulse blue LED to show we send stop condition
printf("%s ", I2C_MASTER_RC_NONE==i2c_master_stop(BUSVOODOO_I2C) ? "sent" : "error");
}
printf("\n");
} else if (1==length && 'u'==action[0]) { // sleep us
if (!perform) {
return true;
}
printf("wait for %u us\n", repetition);
sleep_us(repetition); // sleep
} else if (1==length && 'm'==action[0]) { // sleep ms
if (!perform) {
return true;
}
printf("wait for %u ms\n", repetition);
sleep_ms(repetition); // sleep
} else if ('0'==action[0]) { // send digit
if (1==length) { // just send 0
if (!perform) {
return true;
}
for (uint32_t i=0; i<repetition; i++) {
busvoodoo_i2c_write(0); // write to I2C
}
} else if ('x'==action[1] || 'b'==action[1]) { // send hex/binary
return busvoodoo_i2c_action(action+1, repetition, perform); // just retry without leading 0
} else if (action[1]>='0' && action[1]<='9') { // send decimal
return busvoodoo_i2c_action(action+1, repetition, perform); // just retry without leading 0
} else if ('r'==action[1] && 2==length) { // select slave to read
busvoodoo_i2c_select(0, false); // select slave 0 to read
} else if ('w'==action[1] && 2==length) { // select slave to write
busvoodoo_i2c_select(0, true); // select slave 0 to write
} else { // malformed action
return false;
}
} else if ('x'==action[0] && length>1) { // send hexadecimal value
for (uint32_t i=1; i<length; i++) { // check string
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
return false; // not an hexadecimal string
}
}
if (!perform) {
return true;
}
uint32_t value = strtol(&action[1], NULL, 16); // get hex value
for (uint32_t i=0; i<repetition; i++) {
if ('r'==action[length-1]) {
busvoodoo_i2c_select(value, false); // select slave to read
} else if ('w'==action[length-1]) {
busvoodoo_i2c_select(value, true); // select slave to write
} else {
busvoodoo_i2c_write(value); // write to I2C
}
}
} else if ('b'==action[0] && length>1) { // send binary value
for (uint32_t i=1; i<length; i++) { // check string
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
return false; // not a binary string
}
}
if (!perform) {
return true;
}
uint32_t value = strtol(&action[1], NULL, 2); // get binary value
for (uint32_t i=0; i<repetition; i++) {
if ('r'==action[length-1]) {
busvoodoo_i2c_select(value, false); // select slave to read
} else if ('w'==action[length-1]) {
busvoodoo_i2c_select(value, true); // select slave to write
} else {
busvoodoo_i2c_write(value); // write to I2C
}
}
} else if (action[0]>='1' && action[0]<='9') { // send decimal value
for (uint32_t i=1; i<length; i++) { // check string
if (!((action[i]>='0' && action[i]<='9') || ('w'==action[i] && i==length-1))) { // check for decimal character or r/w flag
return false; // not a decimal string
}
}
if (!perform) {
return true;
}
uint32_t value = strtol(&action[0], NULL, 10); // get decimal value
for (uint32_t i=0; i<repetition; i++) {
if ('r'==action[length-1]) {
busvoodoo_i2c_select(value, false); // select slave to read
} else if ('w'==action[length-1]) {
busvoodoo_i2c_select(value, true); // select slave to write
} else {
busvoodoo_i2c_write(value); // write to I2C
}
}
} else if (length>=2 && ('"'==action[0] || '\''==action[0]) && (action[length-1]==action[0])) { // send ASCII character
if (!perform) {
return true;
}
for (uint32_t r=0; r<repetition; r++) {
for (uint32_t i=1; i<length-1; i++) { // go through string
busvoodoo_i2c_write(action[i]); // write to I2C
}
}
} else { // malformed action
return false;
}
return true; // all went well
}
// command handlers
static void busvoodoo_i2c_command_reset(void* argument)
{
(void)argument; // we won't use the argument
i2c_master_reset(BUSVOODOO_I2C); // reset the I2C peripheral since it might be stuck
i2c_master_setup(BUSVOODOO_I2C, busvoodoo_i2c_speed); // re-setup I2C
printf("I2C peripheral reset\n");
}
static void busvoodoo_i2c_command_actions(void* argument)
{
if (NULL==argument || 0==strlen(argument)) {
printf("available actions (separated by space or ,):\n");
printf("[/]\tsend start/stop conditions\n");
printf("0x0r\tselect slave with I2C address to read\n");
printf("0x0w\tselect slave with I2C address to write\n");
printf("0\twrite decimal value\n");
printf("0x0\twrite hexadecimal value\n");
printf("0b0\twrite binary value\n");
printf("\"a\"/'a'\twrite ASCII characters\n");
printf("r\tread value\n");
printf("u/m\twait 1 us/ms\n");
printf(":n\trepeat action n times\n");
return;
}
// copy argument since it will be modified
char* copy = calloc(strlen(argument)+1, sizeof(char));
if (!copy) {
while (true);
}
strncpy(copy, argument, strlen(argument)+1);
// verify and perform actions
if (!busvoodoo_global_actions(copy, false, &busvoodoo_i2c_action)) { // verify actions
printf("malformed action(s)\n");
} else { // action are ok
busvoodoo_global_actions(argument, true, &busvoodoo_i2c_action); // perform action
}
free(copy); // release memory
}
static void busvoodoo_i2c_command_scan(void* argument)
{
(void)argument; // we won't use the argument
if (!i2c_master_check_signals(BUSVOODOO_I2C)) { // ensure SCL and SDA are high
printf("SCL or/and SDA are low. The signals need to be pulled up\n");
if (busvoodoo_i2c_embedded_pullup) {
printf("set pull-up voltage with LV\n");
}
busvoodoo_leds_blink(0.5, 0.5); // show error on LEDs
return; // stop here
} else {
busvoodoo_led_blue_off(); // clear blinking
}
printf("scanning for I2C slaves\n");
int16_t i2c_slaves = 0; // number of slaves found
// check for I2C slaves by going through the address space
printf("I2C slaves found: ");
for (uint16_t address=0; address < (1<<busvoodoo_i2c_addressbits); address++) {
busvoodoo_led_blue_pulse(BUSVOODOO_LED_PULSE); // pulse blue LED to show transmission
switch (i2c_master_select_slave(BUSVOODOO_I2C, address, 10==busvoodoo_i2c_addressbits, false)) { // try to select slave (includes start condition)
case I2C_MASTER_RC_NONE: // slave found
busvoodoo_led_blue_pulse(BUSVOODOO_LED_PULSE); // pulse blue LED to show we found a slave
printf((busvoodoo_i2c_addressbits>7) ? "0x%03x " : "0x%02x ", address); // display address
i2c_slaves++; // increase slave count
break;
case I2C_MASTER_RC_START_STOP_IN_PROGESS: // I2C peripheral error
printf("start condition failed\n"); // show error to user
i2c_slaves = -2; // remember error
break; // stop scanning
case I2C_MASTER_RC_NOT_MASTER: // start condition failed
i2c_master_reset(BUSVOODOO_I2C); // reset the I2C peripheral since it might be stuck
printf("start condition failed\n"); // show error to user
i2c_slaves = -1; // remember error
break; // stop scanning
case I2C_MASTER_RC_NAK: // slave did not respond
break; // nothing to do
case I2C_MASTER_RC_BUS_ERROR:
printf("error detected on bus\n");
i2c_slaves = -2; // remember error
break;
default: // unexpected error
printf("error occurred\n");
i2c_slaves = -1; // remember error
break;
}
if (i2c_slaves<0) { // error happened
busvoodoo_leds_blink(0.5, 0.5); // show error on LEDs
if (-1==i2c_slaves) { // just end communication
i2c_master_stop(BUSVOODOO_I2C); // send stop condition
} else if (-2==i2c_slaves) { // reset peripheral
busvoodoo_i2c_command_reset(NULL);
}
break; // stop scan
} else {
if (I2C_MASTER_RC_NONE!=i2c_master_stop(BUSVOODOO_I2C)) { // stop stop condition
i2c_master_reset(BUSVOODOO_I2C); // reset the I2C peripheral since it might be stuck
printf("stop condition failed\n"); // show error to user
busvoodoo_leds_blink(0.5, 0.5); // show error on LEDs
i2c_slaves = -1; // remember error
break;
}
}
}
printf("\n");
if (i2c_slaves>=0) {
printf("%u slave(s) found\n", i2c_slaves); // show summary
}
}
static const struct menu_command_t busvoodoo_i2c_commands[] = {
{
.shortcut = 'r',
.name = "reset_i2c",
.command_description = "reset I2C peripheral",
.argument = MENU_ARGUMENT_NONE,
.argument_description = NULL,
.command_handler = &busvoodoo_i2c_command_reset,
},
{
.shortcut = 'a',
.name = "action",
.command_description = "perform protocol actions",
.argument = MENU_ARGUMENT_STRING,
.argument_description = "[actions]",
.command_handler = &busvoodoo_i2c_command_actions,
},
{
.shortcut = 's',
.name = "scan",
.command_description = "scan for slave devices",
.argument = MENU_ARGUMENT_NONE,
.argument_description = NULL,
.command_handler = &busvoodoo_i2c_command_scan,
},
};
const struct busvoodoo_mode_t busvoodoo_i2c_mode = {
.name = "i2c",
.description = "Inter-Integrated Circuit",
.full_only = false,
.setup = &busvoodoo_i2c_setup,
.commands = busvoodoo_i2c_commands,
.commands_nb = LENGTH(busvoodoo_i2c_commands),
.exit = &busvoodoo_i2c_exit,
};
i2c_master.h
library to communicate using I2C as master (API)
menu_command_t
command menu entry
Definition: menu.h:32
i2c_master_stop
enum i2c_master_rc i2c_master_stop(uint32_t i2c)
sent stop condition
Definition: i2c_master.c:464
BUSVOODOO_LED_PULSE
#define BUSVOODOO_LED_PULSE
recommended duration in ms for pulsing LEDs to show activity
Definition: busvoodoo_global.h:112
busvoodoo_i2c_command_reset
static void busvoodoo_i2c_command_reset(void *argument)
command to reset I2C peripheral
Definition: busvoodoo_i2c.c:407
busvoodoo_global.h
BusVoodoo global definitions and methods (API)
i2c_master_select_slave
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
busvoodoo_i2c_write
static void busvoodoo_i2c_write(uint8_t data)
write to I2C
Definition: busvoodoo_i2c.c:191
I2C_MASTER_RC_NOT_RECEIVE
not in receive mode
Definition: i2c_master.h:29
busvoodoo_oled_text_pinout
void busvoodoo_oled_text_pinout(const char *pins[10], bool io_connector)
draw pin names on bottom (blue) part in display buffer
Definition: busvoodoo_oled.c:148
busvoodoo_mode_t::name
const char * name
name of the mode (i.e.
Definition: busvoodoo_global.h:116
i2c_master_read
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
busvoodoo_led_blue_pulse
void busvoodoo_led_blue_pulse(uint32_t ms)
pulse blue LED for short duration
Definition: busvoodoo_global.c:468
i2c_master_reset
void i2c_master_reset(uint32_t i2c)
reset I2C peripheral, fixing any locked state
Definition: i2c_master.c:254
I2C_MASTER_RC_BUS_ERROR
an error on the I2C bus occurred
Definition: i2c_master.h:32
i2c_master_start
enum i2c_master_rc i2c_master_start(uint32_t i2c)
send start condition
Definition: i2c_master.c:284
busvoodoo_oled_update
void busvoodoo_oled_update(void)
update OLED display RAM with current display buffer
Definition: busvoodoo_oled.c:289
busvoodoo_i2c_speed
uint16_t busvoodoo_i2c_speed
I2C speed (in kHz)
Definition: busvoodoo_i2c.c:53
busvoodoo_global_pinout_rscan
const char * busvoodoo_global_pinout_rscan[5]
RS/CAN connector pinout.
Definition: busvoodoo_global.c:63
global.h
global definitions and methods (API)
busvoodoo_i2c_exit
static void busvoodoo_i2c_exit(void)
exit I2C mode
Definition: busvoodoo_i2c.c:154
sleep_us
void sleep_us(uint32_t duration)
go to sleep for some microseconds
Definition: global.c:102
I2C_MASTER_RC_NOT_MASTER
not in master mode
Definition: i2c_master.h:27
busvoodoo_full
bool busvoodoo_full
is the BusVoodoo board fully populated (with HV voltage regulator, RS-232, RS-485, CAN transceiver on the back side)
Definition: busvoodoo_global.c:70
busvoodoo_i2c_select
static void busvoodoo_i2c_select(uint16_t slave, bool write)
select I2C slave
Definition: busvoodoo_i2c.c:224
busvoodoo_led_blue_off
void busvoodoo_led_blue_off(void)
switch off blue LED
Definition: busvoodoo_global.c:426
i2c_master_write
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
I2C_MASTER_RC_START_STOP_IN_PROGESS
a start or stop condition is already in progress
Definition: i2c_master.h:26
BUSVOODOO_I2C
#define BUSVOODOO_I2C
I2C peripheral.
Definition: busvoodoo_i2c.c:41
busvoodoo_i2c_embedded_pullup
bool busvoodoo_i2c_embedded_pullup
if embedded or external pull-up resistors are use
Definition: busvoodoo_i2c.c:57
i2c_master_setup
void i2c_master_setup(uint32_t i2c, uint16_t frequency)
setup I2C peripheral
Definition: i2c_master.c:173
menu_command_t::shortcut
char shortcut
short command code (0 if not available)
Definition: menu.h:33
busvoodoo_leds_blink
void busvoodoo_leds_blink(double period, double duty)
set LED blinking pattern
Definition: busvoodoo_global.c:511
i2c_master_release
void i2c_master_release(uint32_t i2c)
release I2C peripheral
Definition: i2c_master.c:211
busvoodoo_global_pinout_io
const char * busvoodoo_global_pinout_io[10]
I/O connector pinout.
Definition: busvoodoo_global.c:62
busvoodoo_i2c_setup
static bool busvoodoo_i2c_setup(char **prefix, const char *line)
setup I2C mode
Definition: busvoodoo_i2c.c:64
busvoodoo_global_string
char busvoodoo_global_string[64]
shared string buffer, i.e.
Definition: busvoodoo_global.c:72
busvoodoo_i2c_commands
static const struct menu_command_t busvoodoo_i2c_commands[]
I2C menu commands.
Definition: busvoodoo_i2c.c:523
snprintf
size_t snprintf(char *str, size_t size, const char *format,...)
print format string on string or user output
Definition: print.c:458
busvoodoo_global_actions
bool busvoodoo_global_actions(char *actions, bool perform, bool(*action_handler)(const char *action, uint32_t repetition, bool perform))
parse and perform actions
Definition: busvoodoo_global.c:561
busvoodoo_i2c_action
static bool busvoodoo_i2c_action(const char *action, uint32_t repetition, bool perform)
perform I2C action
Definition: busvoodoo_i2c.c:265
sleep_ms
void sleep_ms(uint32_t duration)
go to sleep for some milliseconds
Definition: global.c:117
printf
size_t printf(const char *format,...)
print format string on user output
Definition: print.c:448
I2C_MASTER_RC_NOT_READY
slave is not read (previous operations has been nacked)
Definition: i2c_master.h:30
print.h
printing utilities to replace the large printf from the standard library (API)
busvoodoo_oled_text_left
void busvoodoo_oled_text_left(char *text)
draw mode text on top (yellow) left side in display buffer
Definition: busvoodoo_oled.c:118
busvoodoo_embedded_pullup
float busvoodoo_embedded_pullup(bool on)
enable embedded pull-up resistors
Definition: busvoodoo_global.c:373
busvoodoo_i2c_read
static void busvoodoo_i2c_read(void)
read from I2C
Definition: busvoodoo_i2c.c:161
LENGTH
#define LENGTH(x)
get the length of an array
Definition: global.h:26
i2c_master_check_signals
bool i2c_master_check_signals(uint32_t i2c)
check if SDA and SCL signals are high
Definition: i2c_master.c:225
busvoodoo_i2c_mode
const struct busvoodoo_mode_t busvoodoo_i2c_mode
I2C mode interface definition.
Definition: busvoodoo_i2c.c:550
I2C_MASTER_RC_NOT_TRANSMIT
not in transmit mode
Definition: i2c_master.h:28
busvoodoo_oled.h
library to show BusVoodoo mode information on SSD1306 OLED display: name, activity, pinout (API)
busvoodoo_i2c_setting
static enum busvoodoo_i2c_setting_t busvoodoo_i2c_setting
current mode setup stage
I2C_MASTER_RC_NONE
no error
Definition: i2c_master.h:25
busvoodoo_mode_t
BusVoodoo mode interface.
Definition: busvoodoo_global.h:115
busvoodoo_i2c_command_actions
static void busvoodoo_i2c_command_actions(void *argument)
command to perform actions
Definition: busvoodoo_i2c.c:419
busvoodoo_i2c_addressbits
uint8_t busvoodoo_i2c_addressbits
I2C address bits (7 or 10)
Definition: busvoodoo_i2c.c:55
busvoodoo_i2c.h
BusVoodoo I²C mode (API)
busvoodoo_i2c_command_scan
static void busvoodoo_i2c_command_scan(void *argument)
command to scan for slave devices
Definition: busvoodoo_i2c.c:453
I2C_MASTER_RC_NAK
not acknowledge received
Definition: i2c_master.h:31