mirror of
https://github.com/OpenEPaperLink/OpenEPaperLink.git
synced 2026-03-21 07:06:36 +01:00
We currently have two ways of undefining the PowerPin in software for the ESP32
For once we can set POWER_NO_SOFT_POWER which will lead to some helpful screen
messages _but_ will still require the definition of the FLASHER_AP_POWER pin.
The second way (which was replaced with POWER_NO_SOFT_POWER) allowed to set the
powerPin array to {-1} to indicate that the pin is undefined. This would then be
handled in pretty far down the call stack right before toggeling the pin in powerControl:
```
void powerControl(bool powerState, uint8_t* pin, uint8_t pincount) {
if (pin[0] == -1) return;
```
This however is leading to an error: pin is n pointer (here an array with additional length)
to an uint8_t which can never be -1. Therefore the check wont ever be reached and an invalid
gpio number is passed to the gpio hal.
This caused the error:
```
E (XXXX) gpio: gpio_set_level(226): GPIO output gpio_num error
```
to show up in the logs.
We are now proposing three seperate changes to mitigate this behaviour:
1) We are addng the POWER_NO_SOFT_POWER to the Wemos and the M5Stack boards default configs
for new users to find.
2) We are replacing the pin[0] check in powerControl with a check on the pincount and a
nullptr check as the zbs_interface->begin() allows for no powerPin to be passed in which
case we are dereferencing a nullptr.
3) ZBS_interface->begin() is losing its powerPin related default configurations and
sanity checks are put in place before every calling.
We have opted to do 3) in this way and not adding the checked into the ZBS_interface->begin()
function which is also passed an uint8_t pointer to keep the API of the class stable
for reuse in other projects. Changing the interface however would be ideal here
Signed-off-by: Mimoja <git@mimoja.de>
64 lines
1.7 KiB
C++
64 lines
1.7 KiB
C++
#pragma once
|
|
#include <stdio.h>
|
|
#include <stdint.h>
|
|
#include <SPI.h>
|
|
|
|
/* Autor: Aaron Christophel ATCnetz.de */
|
|
#include <Arduino.h>
|
|
|
|
class ZBS_interface
|
|
{
|
|
public:
|
|
uint8_t begin(uint8_t SS, uint8_t CLK, uint8_t MOSI, uint8_t MISO, uint8_t RESET, uint8_t* POWER, uint8_t powerPins, uint32_t spi_speed = 8000000);
|
|
void setSpeed(uint32_t speed);
|
|
void set_power(uint8_t state);
|
|
void enable_debug();
|
|
void reset();
|
|
void send_byte(uint8_t data);
|
|
uint8_t read_byte();
|
|
void write_byte(uint8_t cmd, uint8_t addr, uint8_t data);
|
|
uint8_t read_byte(uint8_t cmd, uint8_t addr);
|
|
void write_flash(uint16_t addr, uint8_t data);
|
|
uint8_t read_flash(uint16_t addr);
|
|
void write_ram(uint8_t addr, uint8_t data);
|
|
uint8_t read_ram(uint8_t addr);
|
|
void write_sfr(uint8_t addr, uint8_t data);
|
|
uint8_t read_sfr(uint8_t addr);
|
|
uint8_t check_connection();
|
|
uint8_t select_flash(uint8_t page);
|
|
void erase_flash();
|
|
void erase_infoblock();
|
|
~ZBS_interface();
|
|
|
|
private:
|
|
SPIClass *spi = NULL;
|
|
SPISettings spiSettings;
|
|
uint8_t _SS_PIN = -1;
|
|
uint8_t _CLK_PIN = -1;
|
|
uint8_t _MOSI_PIN = -1;
|
|
uint8_t _MISO_PIN = -1;
|
|
uint8_t _RESET_PIN = -1;
|
|
uint8_t* _POWER_PIN = nullptr;
|
|
uint8_t _POWER_PINS = 1;
|
|
int ZBS_spi_delay = 1;
|
|
uint8_t spi_ready = 0;
|
|
uint32_t after_byte_delay = 10;
|
|
|
|
typedef enum
|
|
{
|
|
ZBS_CMD_W_RAM = 0x02,
|
|
ZBS_CMD_R_RAM = 0x03,
|
|
ZBS_CMD_W_FLASH = 0x08,
|
|
ZBS_CMD_R_FLASH = 0x09,
|
|
ZBS_CMD_W_SFR = 0x12,
|
|
ZBS_CMD_R_SFR = 0x13,
|
|
ZBS_CMD_ERASE_FLASH = 0x88,
|
|
ZBS_CMD_ERASE_INFOBLOCK = 0x48,
|
|
} ZBS_CMD_LIST;
|
|
|
|
typedef enum
|
|
{
|
|
ZBS_ON = 1,
|
|
ZBS_OFF = 0,
|
|
} ZBS_POWER_STATE;
|
|
}; |