diff --git a/src/App.cpp b/src/App.cpp index 0320ac9..e4dcc62 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -17,9 +17,12 @@ App::App() { uint32_t App::main() { - DemoTask demoTask{}; + ESP_LOGI(__FILE__, "Running App::main()"); - demoTask.start("BlinkTask", 2048, 5, 1); + static DemoTask demoTask{}; + + ESP_LOGI(__FILE__, "Starting DemoTask"); + demoTask.start("DemoTask", 4096, 5, 1); return 1; } diff --git a/src/DemoTask.cpp b/src/DemoTask.cpp index 13a1d56..a5bad7b 100644 --- a/src/DemoTask.cpp +++ b/src/DemoTask.cpp @@ -15,30 +15,18 @@ DemoTask::DemoTask() { void DemoTask::run() { - /* - ESP_LOGI(TAG, "Example configured to blink GPIO LED!"); - gpio_reset_pin(gpio_onboardLed); - gpio_set_direction(gpio_onboardLed, GPIO_MODE_OUTPUT); + ESP_LOGI(__FILE__, "Demo Task: run()"); - while (1) { - ESP_LOGI(TAG, "Turning the LED %s!", ledState == true ? "ON" : "OFF"); - gpio_set_level(gpio_onboardLed, ledState); - ledState = !ledState; - vTaskDelay(blinkTime / portTICK_PERIOD_MS); - } - */ + ssd_595_t dev = { gpio_ssd_data, gpio_ssd_clk, gpio_ssd_latch, true }; + SsdInterface ssd(&dev, ssdDigits); - ESP_LOGI(__FILE__, "Demo Task"); - - SsdInterface ssd(gpio_ssd_data, gpio_ssd_clk, gpio_ssd_latch, ssdDigits); uint32_t delay = 500; // ms - uint8_t byte = 0x00; + uint8_t digit = 0; while(1) { - ESP_LOGI(__FILE__, "Shifting out byte %02hhx", byte); - - ssd.writeRaw(&byte, 1); - byte++; + ssd.writeRaw(&digitMap[digit], 1); + digit++; + if(digit >= 16) digit = 0; vTaskDelay(delay / portTICK_PERIOD_MS); } diff --git a/src/SsdInterface.cpp b/src/SsdInterface.cpp index 5fdd61d..a0522dc 100644 --- a/src/SsdInterface.cpp +++ b/src/SsdInterface.cpp @@ -1,11 +1,9 @@ #include "SsdInterface.hpp" -SsdInterface::SsdInterface(const uint8_t dataPin, const uint8_t clockPin, const uint8_t latchPin, size_t numDigits) : numDigits_(numDigits) { +SsdInterface::SsdInterface(const ssd_595_t* device, size_t numDigits) : device_(device), numDigits_(numDigits) { - // create device - static ssd_595_t dev = { (gpio_num_t)dataPin, (gpio_num_t)clockPin, (gpio_num_t)latchPin }; - device_ = &dev; + shiftInit(device_); } diff --git a/src/SsdInterface.hpp b/src/SsdInterface.hpp index 8521a90..9387483 100644 --- a/src/SsdInterface.hpp +++ b/src/SsdInterface.hpp @@ -10,7 +10,7 @@ class SsdInterface { public: - SsdInterface(const uint8_t dataPin, const uint8_t clockPin, const uint8_t latchPinPin, size_t numDigits); + SsdInterface(const ssd_595_t* device, size_t numDigits); ~SsdInterface() = default; // Outputs the data straight to hardware, mostly for testing purposes @@ -35,7 +35,7 @@ public: private: - ssd_595_t* device_; + const ssd_595_t* device_; size_t numDigits_; // number of chained digits uint8_t* data_; // pointer to the data written diff --git a/src/TaskBase.cpp b/src/TaskBase.cpp index ca6ff53..e1cedca 100644 --- a/src/TaskBase.cpp +++ b/src/TaskBase.cpp @@ -1,6 +1,8 @@ #include "TaskBase.hpp" +#include "esp_log.h" + void TaskBase::start(const char* name, uint32_t stackSize, UBaseType_t priority, BaseType_t core) { xTaskCreatePinnedToCore(&TaskBase::taskEntryPoint, name, stackSize, this, priority, &handle, core); return; diff --git a/src/drivers/ssd.c b/src/drivers/ssd.c index 26aa716..525f2fb 100644 --- a/src/drivers/ssd.c +++ b/src/drivers/ssd.c @@ -2,6 +2,7 @@ #include "ssd.h" #include "esp_rom_sys.h" +#include "esp_log.h" #ifdef __cplusplus extern "C" { @@ -9,23 +10,28 @@ extern "C" { inline void pulse(gpio_num_t pin) { gpio_set_level(pin, 1); - esp_rom_delay_us(1); gpio_set_level(pin, 0); - esp_rom_delay_us(1); } void shiftInit(const ssd_595_t* device) { + + gpio_reset_pin(device->dataPin); + gpio_reset_pin(device->clockPin); + gpio_reset_pin(device->latchPin); + gpio_config_t ioConfig = { .mode = GPIO_MODE_OUTPUT, .pin_bit_mask = (1ULL << device->dataPin) | (1ULL << device->clockPin) | - (1ULL << device->latchPin) + (1ULL << device->latchPin), }; gpio_config(&ioConfig); gpio_set_level(device->dataPin, 0); gpio_set_level(device->clockPin, 0); gpio_set_level(device->latchPin, 0); + + ESP_LOGI(__FILE__, "ssd_595 initialized"); } void addDecimal(uint8_t* data) { @@ -34,8 +40,9 @@ void addDecimal(uint8_t* data) { } void shiftByte(const ssd_595_t* device, uint8_t byte) { - for(int i = 0; i < __CHAR_BIT__; i++) { - gpio_set_level(device->dataPin, (byte >> i) & 0x1); + for(int i = 0; i < __CHAR_BIT__ ; i++) { + uint32_t level = ((byte >> i) & 0x1) ^ device->commonCathode; + gpio_set_level(device->dataPin, level); pulse(device->clockPin); } pulse(device->latchPin); diff --git a/src/drivers/ssd.h b/src/drivers/ssd.h index da79d27..17cdebd 100644 --- a/src/drivers/ssd.h +++ b/src/drivers/ssd.h @@ -14,6 +14,7 @@ typedef struct { gpio_num_t dataPin; gpio_num_t clockPin; gpio_num_t latchPin; + bool commonCathode; // false = common anode } ssd_595_t; // encoding of digits on the seven segment display