worked on SPI, fixed some bugs
adjusted LCD code added code for INA3221 worked on UI
This commit is contained in:
22
io/GPIO.h
22
io/GPIO.h
@@ -98,6 +98,11 @@
|
||||
|
||||
#include "driver/gpio.h"
|
||||
|
||||
// NOTE from the manual
|
||||
// GPIO 6-11 are usually used for SPI flash.
|
||||
// GPIO 34-39 can only be set as input mode and do not have software pullup or pulldown functions.
|
||||
|
||||
|
||||
struct MyGPIO {
|
||||
|
||||
static inline bool get(const uint8_t num) {
|
||||
@@ -134,7 +139,7 @@
|
||||
io_conf.pin_bit_mask = (1<<num);
|
||||
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
||||
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
|
||||
gpio_config(&io_conf);
|
||||
ESP_ERROR_CHECK(gpio_config(&io_conf));
|
||||
}
|
||||
|
||||
static inline void setInput(const uint8_t num) {
|
||||
@@ -148,7 +153,20 @@
|
||||
io_conf.pin_bit_mask = (1<<num);
|
||||
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
||||
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
|
||||
gpio_config(&io_conf);
|
||||
ESP_ERROR_CHECK(gpio_config(&io_conf));
|
||||
}
|
||||
|
||||
static inline void setInputPullUp(const uint8_t num) {
|
||||
setInputPullUp((gpio_num_t)num);
|
||||
}
|
||||
static inline void setInputPullUp(const gpio_num_t num) {
|
||||
gpio_config_t io_conf;
|
||||
io_conf.intr_type = GPIO_INTR_DISABLE;
|
||||
io_conf.mode = GPIO_MODE_INPUT;
|
||||
io_conf.pin_bit_mask = (1<<num);
|
||||
io_conf.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
||||
io_conf.pull_up_en = GPIO_PULLUP_ENABLE; // here
|
||||
ESP_ERROR_CHECK(gpio_config(&io_conf));
|
||||
}
|
||||
|
||||
static void toggleBuiltInLED() {
|
||||
|
||||
28
io/HardSPI.h
28
io/HardSPI.h
@@ -51,7 +51,7 @@ private:
|
||||
buscfg.sclk_io_num = PIN_NUM_CLK;
|
||||
buscfg.quadwp_io_num = -1;
|
||||
buscfg.quadhd_io_num = -1;
|
||||
buscfg.max_transfer_sz = MAX_LEN;//320*240*2;
|
||||
buscfg.max_transfer_sz = MAX_LEN;
|
||||
buscfg.flags = 0;
|
||||
buscfg.intr_flags = 0;
|
||||
|
||||
@@ -80,9 +80,12 @@ public:
|
||||
void write(const uint8_t* data, size_t len) {
|
||||
|
||||
spi_transaction_t t;
|
||||
memset(&t, 0, sizeof(spi_transaction_t));
|
||||
|
||||
while(len > 0) {
|
||||
|
||||
// ensure the transaction is reset to defaults.
|
||||
// this is mandatory! as the ESP adjusts some parameters while/after sending!
|
||||
memset(&t, 0, sizeof(spi_transaction_t));
|
||||
|
||||
const size_t chunkLen = min(MAX_LEN, (len));
|
||||
t.length = 8 * chunkLen; // in bits
|
||||
@@ -136,6 +139,23 @@ public:
|
||||
|
||||
}
|
||||
|
||||
/** send 4 bytes onto the bus while reading 4 bytes response */
|
||||
uint8_t readWriteByte(uint8_t write) {
|
||||
|
||||
spi_transaction_t t;
|
||||
memset(&t, 0, sizeof(spi_transaction_t));
|
||||
t.length = 8*1;
|
||||
t.rxlength = 8*1;
|
||||
t.tx_data[0] = (write >> 0) & 0xFF;
|
||||
t.flags = SPI_TRANS_USE_RXDATA | SPI_TRANS_USE_TXDATA;
|
||||
|
||||
esp_err_t ret = spi_device_polling_transmit(spi, &t);
|
||||
ESP_ERROR_CHECK(ret);
|
||||
|
||||
return (static_cast<uint32_t>(t.rx_data[0]));
|
||||
|
||||
}
|
||||
|
||||
/** send 4 bytes onto the bus while reading 4 bytes response */
|
||||
uint32_t readWriteQuad(uint32_t write) {
|
||||
|
||||
@@ -220,6 +240,10 @@ public:
|
||||
ESP_ERROR_CHECK(ret);
|
||||
|
||||
}
|
||||
|
||||
static size_t min(size_t a, size_t b) {
|
||||
return (a < b) ? a : b;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
16
io/SoftI2C.h
16
io/SoftI2C.h
@@ -24,8 +24,7 @@ template <int PIN_SDA, int PIN_SCL, bool fast> class SoftI2C {
|
||||
inline void sclLo() {MyGPIO::clear(PIN_SCL);}
|
||||
|
||||
inline void waitLong() {
|
||||
for (uint8_t i = 0; i < 240; ++i) {
|
||||
__asm__ __volatile__("nop");
|
||||
for (uint16_t i = 0; i < 1024; ++i) {
|
||||
__asm__ __volatile__("nop");
|
||||
}
|
||||
}
|
||||
@@ -33,7 +32,6 @@ template <int PIN_SDA, int PIN_SCL, bool fast> class SoftI2C {
|
||||
inline void waitShort() {
|
||||
for (uint8_t i = 0; i < 240; ++i) {
|
||||
__asm__ __volatile__("nop");
|
||||
__asm__ __volatile__("nop");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,14 +154,14 @@ public:
|
||||
|
||||
// select register(s) to read
|
||||
ok = startWrite(addr);
|
||||
if (!ok) {debugMod(NAME, "failed start write1\n"); return false;}
|
||||
if (!ok) {debugMod(NAME, "failed start write(1)"); return false;}
|
||||
ok = writeByteAndCheck(reg);
|
||||
if (!ok) {debugMod(NAME, "failed select register\n"); return false;}
|
||||
if (!ok) {debugMod(NAME, "failed select register"); return false;}
|
||||
stop();
|
||||
|
||||
// read register(s)
|
||||
ok = startRead(addr);
|
||||
if (!ok) {debugMod(NAME, "failed start write2\n"); return false;}
|
||||
if (!ok) {debugMod(NAME, "failed start write(2)"); return false;}
|
||||
readBytes(dst, len);
|
||||
stop();
|
||||
|
||||
@@ -178,11 +176,11 @@ public:
|
||||
|
||||
// address the slave in write mode and select the first register to read
|
||||
ok = startWrite(addr);
|
||||
if (!ok) {debugMod(NAME, "failed start write\n"); return false;}
|
||||
if (!ok) {debugMod(NAME, "failed start write"); return false;}
|
||||
ok = writeByteAndCheck(reg);
|
||||
if (!ok) {debugMod1(NAME, "failed to select register %d\n", addr); return false;}
|
||||
if (!ok) {debugMod1(NAME, "failed to select register %d", addr); return false;}
|
||||
ok = writeBytesAndCheck(src, len);
|
||||
if (!ok) {debugMod(NAME, "failed to write register contents \n"); return false;}
|
||||
if (!ok) {debugMod(NAME, "failed to write register contents"); return false;}
|
||||
|
||||
// done
|
||||
stop();
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
|
||||
#pragma GCC push_options
|
||||
#pragma GCC optimize ("O3")
|
||||
#pragma GCC optimize ("O2")
|
||||
|
||||
|
||||
template <int PIN_MISO, int PIN_MOSI, int PIN_CLK, bool fast> class SoftSPI {
|
||||
|
||||
Reference in New Issue
Block a user