BV I2C: update to new I2C library
This commit is contained in:
parent
82e33023de
commit
1be97ae21b
|
@ -24,18 +24,23 @@
|
|||
#include <string.h> // string utilities
|
||||
|
||||
/* STM32 (including CM3) libraries */
|
||||
#include <libopencm3/stm32/gpio.h> // general purpose input output library
|
||||
#include <libopencm3/stm32/rcc.h> // real-time control clock library
|
||||
#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_general.h" // I2C utilities
|
||||
#include "i2c_master.h" // I2C utilities
|
||||
#include "busvoodoo_global.h" // BusVoodoo definitions
|
||||
#include "busvoodoo_oled.h" // OLED utilities
|
||||
#include "busvoodoo_i2c.h" // own definitions
|
||||
|
||||
/** @defgroup busvoodoo_i2c I2C peripheral to communicate with I2C devices
|
||||
* @{
|
||||
*/
|
||||
#define BUSVOODOO_I2C I2C2 /**< I2C peripheral */
|
||||
/** @} */
|
||||
|
||||
/** mode setup stage */
|
||||
static enum busvoodoo_i2c_setting_t {
|
||||
BUSVOODOO_I2C_SETTING_NONE,
|
||||
|
@ -113,7 +118,7 @@ static bool busvoodoo_i2c_setup(char** prefix, const char* line)
|
|||
}
|
||||
}
|
||||
if (BUSVOODOO_I2C_SETTING_DONE==busvoodoo_i2c_setting) { // we have all settings, configure I2C
|
||||
i2c_general_setup_master(false); // setup I2C
|
||||
i2c_master_setup(BUSVOODOO_I2C, false); // setup I2C
|
||||
busvoodoo_embedded_pullup(busvoodoo_i2c_embedded_pullup); // set pull-up
|
||||
if (busvoodoo_i2c_embedded_pullup) {
|
||||
printf("set pull-up voltage with LV\n");
|
||||
|
@ -144,7 +149,7 @@ static bool busvoodoo_i2c_setup(char** prefix, const char* line)
|
|||
*/
|
||||
static void busvoodoo_i2c_exit(void)
|
||||
{
|
||||
// TODO release I2C periph
|
||||
i2c_master_release(BUSVOODOO_I2C); // release I2C peripheral
|
||||
busvoodoo_embedded_pullup(false); // disable embedded pull-ups
|
||||
}
|
||||
|
||||
|
@ -156,7 +161,7 @@ static void busvoodoo_i2c_exit(void)
|
|||
static void busvoodoo_i2c_command_scan(void* argument)
|
||||
{
|
||||
(void)argument; // we won't use the argument
|
||||
if (!i2c_general_check()) { // ensure SCL and SDA are high
|
||||
if (!i2c_master_check_signals(BUSVOODOO_I2C)) { // ensure SCL and SDA are high
|
||||
printf("SCL or SDA is low. The signals need to be pulled up\n");
|
||||
if (busvoodoo_i2c_embedded_pullup) {
|
||||
printf("set pull-up voltage with LV\n");
|
||||
|
@ -170,20 +175,20 @@ static void busvoodoo_i2c_command_scan(void* argument)
|
|||
uint16_t i2c_slaves = 0; // number of slaves found
|
||||
// check for I2C slaves by going through the address space
|
||||
for (uint16_t address=0; address < (1<<busvoodoo_i2c_addressbits); address++) {
|
||||
if (!i2c_general_start()) { // send start condition
|
||||
i2c_general_stop(); // send stop condition
|
||||
if (!i2c_master_start(BUSVOODOO_I2C)) { // send start condition
|
||||
i2c_master_stop(BUSVOODOO_I2C); // send stop condition
|
||||
printf("start condition failed\n"); // show error to user
|
||||
led_blink(0.5, 0.5); // show error on LEDs
|
||||
break; // stop scanning
|
||||
} else {
|
||||
busvoodoo_led_blue(100); // pulse blue LED to show transmission
|
||||
}
|
||||
if (i2c_general_select_slave(address, false)) { // try to select slave
|
||||
if (i2c_master_select_slave(BUSVOODOO_I2C, address, false)) { // try to select slave
|
||||
busvoodoo_led_red(100); // pulse red LED to show we found a slave
|
||||
printf((busvoodoo_i2c_addressbits>7) ? "0x%03x " : "0x%02x ", address); // display address
|
||||
i2c_slaves++; // increase slave count
|
||||
}
|
||||
i2c_general_stop(); // send stop condition
|
||||
i2c_master_stop(BUSVOODOO_I2C); // send stop condition
|
||||
}
|
||||
if (i2c_slaves>0) {
|
||||
printf("\n");
|
||||
|
|
Loading…
Reference in New Issue