From 0ef333164bb47956a5ac686f376583e865cedcc4 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Wed, 16 Nov 2022 11:24:33 +1100 Subject: Use underscores instead of dashes in filenames consistently --- src/drivers/include/dac.hpp | 2 +- src/drivers/include/display-init.hpp | 81 ------------ src/drivers/include/display.hpp | 4 +- src/drivers/include/display_init.hpp | 81 ++++++++++++ src/drivers/include/gpio-expander.hpp | 208 ------------------------------- src/drivers/include/gpio_expander.hpp | 208 +++++++++++++++++++++++++++++++ src/drivers/include/i2s_audio_output.hpp | 2 +- src/drivers/include/storage.hpp | 2 +- 8 files changed, 294 insertions(+), 294 deletions(-) delete mode 100644 src/drivers/include/display-init.hpp create mode 100644 src/drivers/include/display_init.hpp delete mode 100644 src/drivers/include/gpio-expander.hpp create mode 100644 src/drivers/include/gpio_expander.hpp (limited to 'src/drivers/include') diff --git a/src/drivers/include/dac.hpp b/src/drivers/include/dac.hpp index b4e95ad4..8c4b6419 100644 --- a/src/drivers/include/dac.hpp +++ b/src/drivers/include/dac.hpp @@ -1,6 +1,6 @@ #pragma once -#include "gpio-expander.hpp" +#include "gpio_expander.hpp" #include #include diff --git a/src/drivers/include/display-init.hpp b/src/drivers/include/display-init.hpp deleted file mode 100644 index f7d287f7..00000000 --- a/src/drivers/include/display-init.hpp +++ /dev/null @@ -1,81 +0,0 @@ -#pragma once - -#include - -namespace drivers { -namespace displays { - -extern const uint8_t kDelayBit; - -struct InitialisationData { - uint8_t num_sequences; - const uint8_t* sequences[4]; -}; - -extern const InitialisationData kST7735R; - -/* - * Valid command bytes that can be sent to ST77XX displays, as well as commands - * for more specific variants. - */ -enum StCommands { - ST77XX_NOP = 0x00, - ST77XX_SWRESET = 0x01, - ST77XX_RDDID = 0x04, - ST77XX_RDDST = 0x09, - - ST77XX_SLPIN = 0x10, - ST77XX_SLPOUT = 0x11, - ST77XX_PTLON = 0x12, - ST77XX_NORON = 0x13, - - ST77XX_INVOFF = 0x20, - ST77XX_INVON = 0x21, - ST77XX_DISPOFF = 0x28, - ST77XX_DISPON = 0x29, - ST77XX_CASET = 0x2A, - ST77XX_RASET = 0x2B, - ST77XX_RAMWR = 0x2C, - ST77XX_RAMRD = 0x2E, - - ST77XX_PTLAR = 0x30, - ST77XX_TEOFF = 0x34, - ST77XX_TEON = 0x35, - ST77XX_MADCTL = 0x36, - ST77XX_COLMOD = 0x3A, - - ST77XX_MADCTL_MY = 0x80, - ST77XX_MADCTL_MX = 0x40, - ST77XX_MADCTL_MV = 0x20, - ST77XX_MADCTL_ML = 0x10, - ST77XX_MADCTL_RGB = 0x00, - - ST77XX_RDID1 = 0xDA, - ST77XX_RDID2 = 0xDB, - ST77XX_RDID3 = 0xDC, - ST77XX_RDID4 = 0xDD, - - ST7735_MADCTL_BGR = 0x08, - ST7735_MADCTL_MH = 0x04, - - ST7735_FRMCTR1 = 0xB1, - ST7735_FRMCTR2 = 0xB2, - ST7735_FRMCTR3 = 0xB3, - ST7735_INVCTR = 0xB4, - ST7735_DISSET5 = 0xB6, - - ST7735_PWCTR1 = 0xC0, - ST7735_PWCTR2 = 0xC1, - ST7735_PWCTR3 = 0xC2, - ST7735_PWCTR4 = 0xC3, - ST7735_PWCTR5 = 0xC4, - ST7735_VMCTR1 = 0xC5, - - ST7735_PWCTR6 = 0xFC, - - ST7735_GMCTRP1 = 0xE0, - ST7735_GMCTRN1 = 0xE1, -}; - -} // namespace displays -} // namespace drivers diff --git a/src/drivers/include/display.hpp b/src/drivers/include/display.hpp index 6caf1571..958218ca 100644 --- a/src/drivers/include/display.hpp +++ b/src/drivers/include/display.hpp @@ -1,9 +1,9 @@ #pragma once #include -#include "display-init.hpp" +#include "display_init.hpp" #include "driver/spi_master.h" -#include "gpio-expander.hpp" +#include "gpio_expander.hpp" #include "lvgl/lvgl.h" #include "result.hpp" diff --git a/src/drivers/include/display_init.hpp b/src/drivers/include/display_init.hpp new file mode 100644 index 00000000..f7d287f7 --- /dev/null +++ b/src/drivers/include/display_init.hpp @@ -0,0 +1,81 @@ +#pragma once + +#include + +namespace drivers { +namespace displays { + +extern const uint8_t kDelayBit; + +struct InitialisationData { + uint8_t num_sequences; + const uint8_t* sequences[4]; +}; + +extern const InitialisationData kST7735R; + +/* + * Valid command bytes that can be sent to ST77XX displays, as well as commands + * for more specific variants. + */ +enum StCommands { + ST77XX_NOP = 0x00, + ST77XX_SWRESET = 0x01, + ST77XX_RDDID = 0x04, + ST77XX_RDDST = 0x09, + + ST77XX_SLPIN = 0x10, + ST77XX_SLPOUT = 0x11, + ST77XX_PTLON = 0x12, + ST77XX_NORON = 0x13, + + ST77XX_INVOFF = 0x20, + ST77XX_INVON = 0x21, + ST77XX_DISPOFF = 0x28, + ST77XX_DISPON = 0x29, + ST77XX_CASET = 0x2A, + ST77XX_RASET = 0x2B, + ST77XX_RAMWR = 0x2C, + ST77XX_RAMRD = 0x2E, + + ST77XX_PTLAR = 0x30, + ST77XX_TEOFF = 0x34, + ST77XX_TEON = 0x35, + ST77XX_MADCTL = 0x36, + ST77XX_COLMOD = 0x3A, + + ST77XX_MADCTL_MY = 0x80, + ST77XX_MADCTL_MX = 0x40, + ST77XX_MADCTL_MV = 0x20, + ST77XX_MADCTL_ML = 0x10, + ST77XX_MADCTL_RGB = 0x00, + + ST77XX_RDID1 = 0xDA, + ST77XX_RDID2 = 0xDB, + ST77XX_RDID3 = 0xDC, + ST77XX_RDID4 = 0xDD, + + ST7735_MADCTL_BGR = 0x08, + ST7735_MADCTL_MH = 0x04, + + ST7735_FRMCTR1 = 0xB1, + ST7735_FRMCTR2 = 0xB2, + ST7735_FRMCTR3 = 0xB3, + ST7735_INVCTR = 0xB4, + ST7735_DISSET5 = 0xB6, + + ST7735_PWCTR1 = 0xC0, + ST7735_PWCTR2 = 0xC1, + ST7735_PWCTR3 = 0xC2, + ST7735_PWCTR4 = 0xC3, + ST7735_PWCTR5 = 0xC4, + ST7735_VMCTR1 = 0xC5, + + ST7735_PWCTR6 = 0xFC, + + ST7735_GMCTRP1 = 0xE0, + ST7735_GMCTRN1 = 0xE1, +}; + +} // namespace displays +} // namespace drivers diff --git a/src/drivers/include/gpio-expander.hpp b/src/drivers/include/gpio-expander.hpp deleted file mode 100644 index 7ae0f107..00000000 --- a/src/drivers/include/gpio-expander.hpp +++ /dev/null @@ -1,208 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include - -#include "driver/i2c.h" -#include "esp_check.h" -#include "esp_err.h" -#include "esp_log.h" -#include "freertos/FreeRTOS.h" - -namespace drivers { - -/** - * Wrapper for interfacing with the PCA8575 GPIO expander. Includes basic - * low-level pin setting methods, as well as higher level convenience functions - * for reading, writing, and atomically interacting with the SPI chip select - * pins. - * - * Each method of this class can be called safely from any thread, and all - * updates are guaranteed to be atomic. Any access to chip select related pins - * should be done whilst holding `cs_lock` (preferably via the helper methods). - */ -class GpioExpander { - public: - GpioExpander(); - ~GpioExpander(); - - static const uint8_t kPca8575Address = 0x20; - static const uint8_t kPca8575Timeout = 100 / portTICK_RATE_MS; - - // Port A: - // 0 - audio power enable - // 1 - usb interface power enable - // 2 - display power enable - // 3 - sd card power enable - // 4 - charge power ok (active low) - // 5 - sd mux switch - // 6 - sd chip select - // 7 - display chip select - // All power switches low, chip selects high, active-low charge power high - static const uint8_t kPortADefault = 0b11010001; - - // Port B: - // 0 - 3.5mm jack detect (active low) - // 1 - dac soft mute switch - // 2 - GPIO - // 3 - GPIO - // 4 - GPIO - // 5 - GPIO - // 6 - GPIO - // 7 - GPIO - // DAC mute output low, everything else is active-low inputs. - static const uint8_t kPortBDefault = 0b11111111; - - /* - * Convenience mehod for packing the port a and b bytes into a single 16 bit - * value. - */ - static uint16_t pack(uint8_t a, uint8_t b) { return ((uint16_t)b) << 8 | a; } - - /* - * Convenience mehod for unpacking the result of `pack` back into two single - * byte port datas. - */ - static std::pair unpack(uint16_t ba) { - return std::pair((uint8_t)ba, (uint8_t)(ba >> 8)); - } - - /* - * Convenience function for running some arbitrary pin writing code, then - * flushing a `Write()` to the expander. Example usage: - * - * ``` - * gpio_.with([&](auto& gpio) { - * gpio.set_pin(AUDIO_POWER_ENABLE, true); - * }); - * ``` - */ - void with(std::function f); - - /** - * Sets the ports on the GPIO expander to the values currently represented - * in `ports`. - */ - esp_err_t Write(void); - - /** - * Reads from the GPIO expander, populating `inputs` with the most recent - * values. - */ - esp_err_t Read(void); - - /* Maps each pin of the expander to its number in a `pack`ed uint16. */ - enum Pin { - // Port A - AUDIO_POWER_ENABLE = 0, - USB_INTERFACE_POWER_ENABLE = 1, - DISPLAY_POWER_ENABLE = 2, - SD_CARD_POWER_ENABLE = 3, - CHARGE_POWER_OK = 4, // Active-low input - SD_MUX_SWITCH = 5, - SD_CHIP_SELECT = 6, - DISPLAY_CHIP_SELECT = 7, - - // Port B - PHONE_DETECT = 8, // Active-high input - DAC_MUTE = 9, - GPIO_1 = 10, - GPIO_2 = 11, - GPIO_3 = 12, - GPIO_4 = 13, - GPIO_5 = 14, - GPIO_6 = 15, - }; - - /* Pins whose access should be guarded by `cs_lock`. */ - enum ChipSelect { - SD_CARD = SD_CHIP_SELECT, - DISPLAY = DISPLAY_CHIP_SELECT, - }; - - /* Nicer value names for use with the SD_MUX_SWITCH pin. */ - enum SdController { - SD_MUX_ESP = 0, - SD_MUX_USB = 1, - }; - - /** - * Returns the current driven status of each of the ports. The first byte is - * port a, and the second byte is port b. - */ - std::atomic& ports() { return ports_; } - - /* - * Sets a single specific pin to the given value. `true` corresponds to - * HIGH, and `false` corresponds to LOW. - * - * Calls to this method will be buffered in memory until a call to `Write()` - * is made. - */ - void set_pin(Pin pin, bool value); - void set_pin(ChipSelect cs, bool value); - - /** - * Returns the input status of each of the ports. The first byte is port a, - * and the second byte is port b. - */ - const std::atomic& inputs() const { return inputs_; } - - /* Returns the most recently cached value of the given pin. Only valid for - * pins used as inputs; to check what value we're driving a pin, use - * `ports()`. - */ - bool get_input(Pin pin) const; - - /* Returns the mutex that must be held whilst pulling a CS pin low. */ - std::mutex& cs_mutex() { return cs_mutex_; } - - /* - * Helper class containing an active `cs_mutex` lock. When an instance of - * this class is destroyed (usually by falling out of scope), the associated - * CS pin will be driven high before the lock is released. - */ - class SpiLock { - public: - SpiLock(GpioExpander& gpio, ChipSelect cs); - ~SpiLock(); - - SpiLock(const SpiLock&) = delete; - - private: - std::scoped_lock lock_; - GpioExpander& gpio_; - ChipSelect cs_; - }; - - /* - * Pulls the given CS pin low to signal that we are about to communicate - * with a particular device, after acquiring a lock on `cs_mutex`. The - * recommended way to safely interact with devices on the SPI bus is to have - * a self-contained block like so: - * - * ``` - * { - * auto lock = AcquireSpiBus(WHATEVER); - * // Do some cool things here. - * } - * ``` - */ - SpiLock AcquireSpiBus(ChipSelect cs); - - // Not copyable or movable. There should usually only ever be once instance - // of this class, and that instance will likely have a static lifetime. - GpioExpander(const GpioExpander&) = delete; - GpioExpander& operator=(const GpioExpander&) = delete; - - private: - std::mutex cs_mutex_; - std::atomic ports_; - std::atomic inputs_; -}; - -} // namespace drivers diff --git a/src/drivers/include/gpio_expander.hpp b/src/drivers/include/gpio_expander.hpp new file mode 100644 index 00000000..7ae0f107 --- /dev/null +++ b/src/drivers/include/gpio_expander.hpp @@ -0,0 +1,208 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +#include "driver/i2c.h" +#include "esp_check.h" +#include "esp_err.h" +#include "esp_log.h" +#include "freertos/FreeRTOS.h" + +namespace drivers { + +/** + * Wrapper for interfacing with the PCA8575 GPIO expander. Includes basic + * low-level pin setting methods, as well as higher level convenience functions + * for reading, writing, and atomically interacting with the SPI chip select + * pins. + * + * Each method of this class can be called safely from any thread, and all + * updates are guaranteed to be atomic. Any access to chip select related pins + * should be done whilst holding `cs_lock` (preferably via the helper methods). + */ +class GpioExpander { + public: + GpioExpander(); + ~GpioExpander(); + + static const uint8_t kPca8575Address = 0x20; + static const uint8_t kPca8575Timeout = 100 / portTICK_RATE_MS; + + // Port A: + // 0 - audio power enable + // 1 - usb interface power enable + // 2 - display power enable + // 3 - sd card power enable + // 4 - charge power ok (active low) + // 5 - sd mux switch + // 6 - sd chip select + // 7 - display chip select + // All power switches low, chip selects high, active-low charge power high + static const uint8_t kPortADefault = 0b11010001; + + // Port B: + // 0 - 3.5mm jack detect (active low) + // 1 - dac soft mute switch + // 2 - GPIO + // 3 - GPIO + // 4 - GPIO + // 5 - GPIO + // 6 - GPIO + // 7 - GPIO + // DAC mute output low, everything else is active-low inputs. + static const uint8_t kPortBDefault = 0b11111111; + + /* + * Convenience mehod for packing the port a and b bytes into a single 16 bit + * value. + */ + static uint16_t pack(uint8_t a, uint8_t b) { return ((uint16_t)b) << 8 | a; } + + /* + * Convenience mehod for unpacking the result of `pack` back into two single + * byte port datas. + */ + static std::pair unpack(uint16_t ba) { + return std::pair((uint8_t)ba, (uint8_t)(ba >> 8)); + } + + /* + * Convenience function for running some arbitrary pin writing code, then + * flushing a `Write()` to the expander. Example usage: + * + * ``` + * gpio_.with([&](auto& gpio) { + * gpio.set_pin(AUDIO_POWER_ENABLE, true); + * }); + * ``` + */ + void with(std::function f); + + /** + * Sets the ports on the GPIO expander to the values currently represented + * in `ports`. + */ + esp_err_t Write(void); + + /** + * Reads from the GPIO expander, populating `inputs` with the most recent + * values. + */ + esp_err_t Read(void); + + /* Maps each pin of the expander to its number in a `pack`ed uint16. */ + enum Pin { + // Port A + AUDIO_POWER_ENABLE = 0, + USB_INTERFACE_POWER_ENABLE = 1, + DISPLAY_POWER_ENABLE = 2, + SD_CARD_POWER_ENABLE = 3, + CHARGE_POWER_OK = 4, // Active-low input + SD_MUX_SWITCH = 5, + SD_CHIP_SELECT = 6, + DISPLAY_CHIP_SELECT = 7, + + // Port B + PHONE_DETECT = 8, // Active-high input + DAC_MUTE = 9, + GPIO_1 = 10, + GPIO_2 = 11, + GPIO_3 = 12, + GPIO_4 = 13, + GPIO_5 = 14, + GPIO_6 = 15, + }; + + /* Pins whose access should be guarded by `cs_lock`. */ + enum ChipSelect { + SD_CARD = SD_CHIP_SELECT, + DISPLAY = DISPLAY_CHIP_SELECT, + }; + + /* Nicer value names for use with the SD_MUX_SWITCH pin. */ + enum SdController { + SD_MUX_ESP = 0, + SD_MUX_USB = 1, + }; + + /** + * Returns the current driven status of each of the ports. The first byte is + * port a, and the second byte is port b. + */ + std::atomic& ports() { return ports_; } + + /* + * Sets a single specific pin to the given value. `true` corresponds to + * HIGH, and `false` corresponds to LOW. + * + * Calls to this method will be buffered in memory until a call to `Write()` + * is made. + */ + void set_pin(Pin pin, bool value); + void set_pin(ChipSelect cs, bool value); + + /** + * Returns the input status of each of the ports. The first byte is port a, + * and the second byte is port b. + */ + const std::atomic& inputs() const { return inputs_; } + + /* Returns the most recently cached value of the given pin. Only valid for + * pins used as inputs; to check what value we're driving a pin, use + * `ports()`. + */ + bool get_input(Pin pin) const; + + /* Returns the mutex that must be held whilst pulling a CS pin low. */ + std::mutex& cs_mutex() { return cs_mutex_; } + + /* + * Helper class containing an active `cs_mutex` lock. When an instance of + * this class is destroyed (usually by falling out of scope), the associated + * CS pin will be driven high before the lock is released. + */ + class SpiLock { + public: + SpiLock(GpioExpander& gpio, ChipSelect cs); + ~SpiLock(); + + SpiLock(const SpiLock&) = delete; + + private: + std::scoped_lock lock_; + GpioExpander& gpio_; + ChipSelect cs_; + }; + + /* + * Pulls the given CS pin low to signal that we are about to communicate + * with a particular device, after acquiring a lock on `cs_mutex`. The + * recommended way to safely interact with devices on the SPI bus is to have + * a self-contained block like so: + * + * ``` + * { + * auto lock = AcquireSpiBus(WHATEVER); + * // Do some cool things here. + * } + * ``` + */ + SpiLock AcquireSpiBus(ChipSelect cs); + + // Not copyable or movable. There should usually only ever be once instance + // of this class, and that instance will likely have a static lifetime. + GpioExpander(const GpioExpander&) = delete; + GpioExpander& operator=(const GpioExpander&) = delete; + + private: + std::mutex cs_mutex_; + std::atomic ports_; + std::atomic inputs_; +}; + +} // namespace drivers diff --git a/src/drivers/include/i2s_audio_output.hpp b/src/drivers/include/i2s_audio_output.hpp index d4f6dae1..dabf1ff0 100644 --- a/src/drivers/include/i2s_audio_output.hpp +++ b/src/drivers/include/i2s_audio_output.hpp @@ -2,7 +2,7 @@ #include "audio_output.hpp" #include "dac.hpp" -#include "gpio-expander.hpp" +#include "gpio_expander.hpp" #include "result.hpp" #include diff --git a/src/drivers/include/storage.hpp b/src/drivers/include/storage.hpp index 3aa2cb92..3dec16a5 100644 --- a/src/drivers/include/storage.hpp +++ b/src/drivers/include/storage.hpp @@ -1,6 +1,6 @@ #pragma once -#include "gpio-expander.hpp" +#include "gpio_expander.hpp" #include -- cgit v1.2.3