Skip to content

Commit

Permalink
new: Add I2C support to ESP32C3
Browse files Browse the repository at this point in the history
  • Loading branch information
lcgamboa committed Dec 25, 2023
1 parent 82f6982 commit e8b30b4
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 66 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ PACKAGE=picsimlab
MAINVER=0
MINORVER=9
VERSION=0.9.1
DATE=231210
DATE=231224
VERSION_STABLE=0.9.1
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ modules:
sha256: 034c935101e706f0fc9fbbf0d0069a795a18c3a8c9fb4f4486306801164a65af
- name: qemu-stm32
buildsystem: simple
build-options:
build-args:
- --share=network
build-commands:
- ./build_libqemu-stm32.sh
- strip build/libqemu-stm32.so
Expand Down
72 changes: 28 additions & 44 deletions src/boards/board_C3_DevKitC.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ static int io2pin(int io) {
static const short int pinmap[31] = {
30, // number of pins
-1, // 1-GND
-1, // 2-3V3
-1, // 3-3V3
-1, // 2-VDD
-1, // 3-VDD
-1, // 4-EN
-1, // 5-GND
4, // 6-GPIO4
Expand All @@ -145,8 +145,8 @@ static const short int pinmap[31] = {
-1, // 10-GND
8, // 11-GPIO8
9, // 12-GPIO9
-1, // 13-5V
-1, // 14-5V
-1, // 13-VIN
-1, // 14-VIN
-1, // 15-GND
-1, // 16-GND
-1, // 17-GND
Expand Down Expand Up @@ -817,30 +817,22 @@ void cboard_C3_DevKitC::PinsExtraConfig(int cfg) {
master_uart[1].rx_pin = io2pin(gpio);
master_uart[1].ctrl_on = 1;
break;
/*
case 29: // I2CEXT0_SCL
master_i2c[0].scl_pin = io2pin(gpio);
master_i2c[0].ctrl_on = 1;
break;
case 30: // I2CEXT0_SDA
master_i2c[0].sda_pin = io2pin(gpio);
master_i2c[0].ctrl_on = 1;
break;

case 53: // I2CEXT0_SCL
master_i2c[0].scl_pin = io2pin(gpio);
master_i2c[0].ctrl_on = 1;
break;
case 54: // I2CEXT0_SDA
master_i2c[0].sda_pin = io2pin(gpio);
master_i2c[0].ctrl_on = 1;
break;

/*
case 64: // VSPIQ
master_spi[1].cipo_pin = io2pin(gpio);
master_spi[1].ctrl_on = 1;
break;

case 95: // I2CEXT1_SCL
master_i2c[1].scl_pin = io2pin(gpio);
master_i2c[1].ctrl_on = 1;
break;
case 96: // I2CEXT1_SDA
master_i2c[1].sda_pin = io2pin(gpio);
master_i2c[1].ctrl_on = 1;
break;

case 198: // U2RXD
master_uart[2].rx_pin = io2pin(gpio);
master_uart[2].ctrl_on = 1;
Expand Down Expand Up @@ -884,16 +876,8 @@ void cboard_C3_DevKitC::PinsExtraConfig(int cfg) {
master_uart[1].tx_pin = io2pin(gpio);
master_uart[1].ctrl_on = 1;
break;
/*
case 29: // I2CEXT0_SCL
master_i2c[0].scl_pin = io2pin(gpio);
master_i2c[0].ctrl_on = 1;
break;
case 30: // I2CEXT0_SDA
master_i2c[0].sda_pin = io2pin(gpio);
master_i2c[0].ctrl_on = 1;
break;

/*
case 61: // HSPICS1
master_spi[0].cs_pin[1] = io2pin(gpio);
master_spi[0].ctrl_on = 1;
Expand Down Expand Up @@ -928,15 +912,6 @@ void cboard_C3_DevKitC::PinsExtraConfig(int cfg) {
master_spi[1].ctrl_on = 1;
break;

case 95: // I2CEXT1_SCL
master_i2c[1].scl_pin = io2pin(gpio);
master_i2c[1].ctrl_on = 1;
break;
case 96: // I2CEXT1_SDA
master_i2c[1].sda_pin = io2pin(gpio);
master_i2c[1].ctrl_on = 1;
break;

case 198: // U2RTXD
master_uart[2].tx_pin = io2pin(gpio);
master_uart[2].ctrl_on = 1;
Expand All @@ -955,6 +930,15 @@ void cboard_C3_DevKitC::PinsExtraConfig(int cfg) {
case 52: // rmt_sig_out1
// printf("RMT channel %i in GPIO %i\n", function - 71, gpio);
break;

case 53: // I2CEXT0_SCL
master_i2c[0].scl_pin = io2pin(gpio);
master_i2c[0].ctrl_on = 1;
break;
case 54: // I2CEXT0_SDA
master_i2c[0].sda_pin = io2pin(gpio);
master_i2c[0].ctrl_on = 1;
break;
}

} break;
Expand Down Expand Up @@ -1060,10 +1044,10 @@ lxString cboard_C3_DevKitC::MGetPinName(int pin) {
pinname = "GND";
break;
case 2:
pinname = "3V3";
pinname = "VDD";
break;
case 3:
pinname = "3V3";
pinname = "VDD";
break;
case 4:
pinname = "RST";
Expand Down Expand Up @@ -1093,10 +1077,10 @@ lxString cboard_C3_DevKitC::MGetPinName(int pin) {
pinname = "IO9";
break;
case 13:
pinname = "5V";
pinname = "VIN";
break;
case 14:
pinname = "5V";
pinname = "VIN";
break;
case 15:
pinname = "GND";
Expand Down
8 changes: 7 additions & 1 deletion src/boards/bsim_qemu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1091,9 +1091,15 @@ void bsim_qemu::pins_reset(void) {
pins[p].ovalue = 0;
pins[p].oavalue = 55;

if (MGetPinName(p + 1).Contains("VDD")) {
if (MGetPinName(p + 1).Contains("VDD") || MGetPinName(p + 1).Contains("VIN")) {
pins[p].value = 1;
pins[p].dir = PD_OUT;
pins[p].ptype = PT_POWER;
}
if (MGetPinName(p + 1).Contains("VSS") || MGetPinName(p + 1).Contains("GND")) {
pins[p].value = 0;
pins[p].dir = PD_OUT;
pins[p].ptype = PT_POWER;
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/lib/rcontrol.cc
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ static char decodess(unsigned char v) {
return 'i';
}
}
#define VTBUFFMAX 400
#define VTBUFFMAX SBUFFMAX
static int Vtcount_in = 0;
unsigned char Vtbuff_in[VTBUFFMAX + 1];

Expand Down Expand Up @@ -295,7 +295,7 @@ static void ProcessInput(const char* msg, input_t* Input, int* ret) {
}

static void ProcessOutput(const char* msg, output_t* Output, int* ret, int full = 0) {
char lstemp[500];
char lstemp[SBUFFMAX + 256];
static unsigned char ss = 0; // seven segment

if (type_is_equal(Output->name, "LD")) {
Expand Down Expand Up @@ -370,12 +370,12 @@ static void ProcessOutput(const char* msg, output_t* Output, int* ret, int full
vt->ReceiveCallback = VtReceiveCallback;
}
if (full) {
snprintf(lstemp, 499, "%s %s= %3i\r\n%s\r\n", msg, Output->name, Vtcount_in, Vtbuff_in);
snprintf(lstemp, SBUFFMAX + 255, "%s %s= %3i\r\n%s\r\n", msg, Output->name, Vtcount_in, Vtbuff_in);
*ret += sendtext(lstemp);
Vtbuff_in[0] = 0;
Vtcount_in = 0;
} else {
snprintf(lstemp, 499, "%s %s= %3i\r\n", msg, Output->name, Vtcount_in);
snprintf(lstemp, SBUFFMAX + 255, "%s %s= %3i\r\n", msg, Output->name, Vtcount_in);
*ret += sendtext(lstemp);
}
} else {
Expand Down
8 changes: 4 additions & 4 deletions tests/i2c/bmp280_sensortest/bmp280_sensortest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
#include <SPI.h>
#include <Adafruit_BMP280.h>

//Adafruit_BMP280 bmp; // use I2C interface
Adafruit_BMP280 bmp(10); // use SPI interface
Adafruit_BMP280 bmp; // use I2C interface
//Adafruit_BMP280 bmp(10); // use SPI interface


Adafruit_Sensor *bmp_temp = bmp.getTemperatureSensor();
Adafruit_Sensor *bmp_pressure = bmp.getPressureSensor();

void setup() {
Serial.begin(9600);
while ( !Serial ) delay(100); // wait for native usb

while ( !Serial ) delay(100); // wait for native usb
unsigned status;
//status = bmp.begin(BMP280_ADDRESS_ALT, BMP280_CHIPID);
status = bmp.begin();
Expand Down
File renamed without changes.
Binary file added tests/i2c/esp32c3_bmp280_i2c.pzw
Binary file not shown.
Binary file added tests/in_out/in_out.zip
Binary file not shown.
Binary file added tests/in_out/in_out_pic18.pzw
Binary file not shown.
4 changes: 1 addition & 3 deletions tests/test_in_out.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,7 @@ static int test_IN_OUT_STM32(void* arg) {
}
register_test("IN/OUT STM32", test_IN_OUT_STM32, NULL);

/*
static int test_IN_OUT_PIC18F(void* arg) {
return in_out_test("SPI PIC18F", "in_out/in_out_p18.pzw");
return in_out_test("SPI PIC18F", "in_out/in_out_pic18.pzw");
}
register_test("IN/OUT PIC18F", test_IN_OUT_PIC18F, NULL);
*/
16 changes: 13 additions & 3 deletions tests/test_spi_i2c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ static int bmp280_test(const char* tname, const char* fname, const char* resp, i
}
}

char buff[256];
char buff[2000];
// read serial console
while (test_serial_recv_str(buff, 256, 1000)) {
while (test_serial_recv_str(buff, 2000, 1000)) {
// printf("%s\n", buff);
}

Expand Down Expand Up @@ -104,4 +104,14 @@ register_test("SPI PIC18F", test_SPI_PIC18F, NULL);
static int test_I2C_PIC18F(void* arg) {
return bmp280_test("I2C PIC18F", "i2c/pic18f_bmp280_i2c.pzw", "T= 35.00 P= 780.00", 1);
}
register_test("I2C PIC18F", test_I2C_PIC18F, NULL);
register_test("I2C PIC18F", test_I2C_PIC18F, NULL);
/*
static int test_SPI_ESP32C3(void* arg) {
return bmp280_test("SPI ESP32C3", "spi/esp32c3_bmp280_spi.pzw", "T= 35.00 P= 780.00\r", 1);
}
register_test("SPI ESP32C3", test_SPI_ESP32C3, NULL);
*/
static int test_I2C_ESP32C3(void* arg) {
return bmp280_test("I2C ESP32C3", "i2c/esp32c3_bmp280_i2c.pzw", "T= 35.00 P= 780.00\r", 1);
}
register_test("I2C ESP32C3", test_I2C_ESP32C3, NULL);
11 changes: 6 additions & 5 deletions tests/tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@

static int sockfd = -1;
static char buff[2048];
// static char cmd[256];

// static void setblock(int sock_descriptor);
static void setnblock(int sock_descriptor);
Expand Down Expand Up @@ -208,19 +207,21 @@ static int vtcount = 0;
static char vtbuffer[VTBSIZE];

int test_serial_vt_init(int partnum) {
char cmd[256];
vtnumber = partnum;

if (vtnumber >= 0) {
sprintf(buff, "set part[%02i].in[00] 129", vtnumber);
return test_send_rcmd(buff);
sprintf(cmd, "set part[%02i].in[00] 129", vtnumber);
return test_send_rcmd(cmd);
}
return 1;
}

int test_serial_vt_end(void) {
if (vtnumber >= 0) {
sprintf(buff, "set part[%02i].in[00] 128", vtnumber);
return test_send_rcmd(buff);
char cmd[256];
sprintf(cmd, "set part[%02i].in[00] 128", vtnumber);
return test_send_rcmd(cmd);
}
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#ifndef TESTS_H
#define TESTS_H

#define MAX_TESTS 20
#define MAX_TESTS 256

// extern int NUM_TESTS;

Expand Down

0 comments on commit e8b30b4

Please sign in to comment.