diff options
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/awinic/aw20216.c | 166 | ||||
-rw-r--r-- | drivers/awinic/aw20216.h | 251 | ||||
-rw-r--r-- | drivers/chibios/spi_master.c | 70 | ||||
-rw-r--r-- | drivers/chibios/spi_master.h | 19 | ||||
-rw-r--r-- | drivers/lcd/st7565.c | 479 | ||||
-rw-r--r-- | drivers/lcd/st7565.h | 215 |
6 files changed, 1189 insertions, 11 deletions
diff --git a/drivers/awinic/aw20216.c b/drivers/awinic/aw20216.c new file mode 100644 index 0000000000..236c42a3cd --- /dev/null +++ b/drivers/awinic/aw20216.c @@ -0,0 +1,166 @@ +/* Copyright 2021 Jasper Chan + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "aw20216.h" +#include "spi_master.h" + +/* The AW20216 appears to be somewhat similar to the IS31FL743, although quite + * a few things are different, such as the command byte format and page ordering. + * The LED addresses start from 0x00 instead of 0x01. + */ +#define AWINIC_ID 0b1010 << 4 + +#define AW_PAGE_FUNCTION 0x00 << 1 // PG0, Function registers +#define AW_PAGE_PWM 0x01 << 1 // PG1, LED PWM control +#define AW_PAGE_SCALING 0x02 << 1 // PG2, LED current scaling control +#define AW_PAGE_PATCHOICE 0x03 << 1 // PG3, Pattern choice? +#define AW_PAGE_PWMSCALING 0x04 << 1 // PG4, LED PWM + Scaling control? + +#define AW_WRITE 0 +#define AW_READ 1 + +#define AW_REG_CONFIGURATION 0x00 // PG0 +#define AW_REG_GLOBALCURRENT 0x01 // PG0 + +// Default value of AW_REG_CONFIGURATION +// D7:D4 = 1011, SWSEL (SW1~SW12 active) +// D3 = 0?, reserved (apparently this should be 1 but it doesn't seem to matter) +// D2:D1 = 00, OSDE (open/short detection enable) +// D0 = 0, CHIPEN (write 1 to enable LEDs when hardware enable pulled high) +#define AW_CONFIG_DEFAULT 0b10110000 +#define AW_CHIPEN 1 + +#ifndef AW_SCALING_MAX +# define AW_SCALING_MAX 150 +#endif + +#ifndef AW_GLOBAL_CURRENT_MAX +# define AW_GLOBAL_CURRENT_MAX 150 +#endif + +#ifndef DRIVER_1_CS +# define DRIVER_1_CS B13 +#endif + +#ifndef DRIVER_1_EN +# define DRIVER_1_EN C13 +#endif + +uint8_t g_spi_transfer_buffer[20] = {0}; +aw_led g_pwm_buffer[DRIVER_LED_TOTAL]; +bool g_pwm_buffer_update_required[DRIVER_LED_TOTAL]; + +bool AW20216_write_register(pin_t slave_pin, uint8_t page, uint8_t reg, uint8_t data) { + // Do we need to call spi_stop() if this fails? + if (!spi_start(slave_pin, false, 0, 16)) { + return false; + } + + g_spi_transfer_buffer[0] = (AWINIC_ID | page | AW_WRITE); + g_spi_transfer_buffer[1] = reg; + g_spi_transfer_buffer[2] = data; + + if (spi_transmit(g_spi_transfer_buffer, 3) != SPI_STATUS_SUCCESS) { + spi_stop(); + return false; + } + spi_stop(); + return true; +} + +bool AW20216_init_scaling(void) { + // Set constant current to the max, control brightness with PWM + aw_led led; + for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { + led = g_aw_leds[i]; + if (led.driver == 0) { + AW20216_write_register(DRIVER_1_CS, AW_PAGE_SCALING, led.r, AW_SCALING_MAX); + AW20216_write_register(DRIVER_1_CS, AW_PAGE_SCALING, led.g, AW_SCALING_MAX); + AW20216_write_register(DRIVER_1_CS, AW_PAGE_SCALING, led.b, AW_SCALING_MAX); + } +#ifdef DRIVER_2_CS + else if (led.driver == 1) { + AW20216_write_register(DRIVER_2_CS, AW_PAGE_SCALING, led.r, AW_SCALING_MAX); + AW20216_write_register(DRIVER_2_CS, AW_PAGE_SCALING, led.g, AW_SCALING_MAX); + AW20216_write_register(DRIVER_2_CS, AW_PAGE_SCALING, led.b, AW_SCALING_MAX); + } +#endif + } + return true; +} + +bool AW20216_soft_enable(void) { + AW20216_write_register(DRIVER_1_CS, AW_PAGE_FUNCTION, AW_REG_CONFIGURATION, AW_CONFIG_DEFAULT | AW_CHIPEN); +#ifdef DRIVER_2_CS + AW20216_write_register(DRIVER_2_CS, AW_PAGE_FUNCTION, AW_REG_CONFIGURATION, AW_CONFIG_DEFAULT | AW_CHIPEN); +#endif + return true; +} + +void AW20216_update_pwm(int index, uint8_t red, uint8_t green, uint8_t blue) { + aw_led led = g_aw_leds[index]; + if (led.driver == 0) { + AW20216_write_register(DRIVER_1_CS, AW_PAGE_PWM, led.r, red); + AW20216_write_register(DRIVER_1_CS, AW_PAGE_PWM, led.g, green); + AW20216_write_register(DRIVER_1_CS, AW_PAGE_PWM, led.b, blue); + } +#ifdef DRIVER_2_CS + else if (led.driver == 1) { + AW20216_write_register(DRIVER_2_CS, AW_PAGE_PWM, led.r, red); + AW20216_write_register(DRIVER_2_CS, AW_PAGE_PWM, led.g, green); + AW20216_write_register(DRIVER_2_CS, AW_PAGE_PWM, led.b, blue); + } +#endif + return; +} + +void AW20216_init(void) { + // All LEDs should start with all scaling and PWM registers as off + setPinOutput(DRIVER_1_EN); + writePinHigh(DRIVER_1_EN); + AW20216_write_register(DRIVER_1_CS, AW_PAGE_FUNCTION, AW_REG_GLOBALCURRENT, AW_GLOBAL_CURRENT_MAX); +#ifdef DRIVER_2_EN + setPinOutput(DRIVER_2_EN); + writePinHigh(DRIVER_2_EN); + AW20216_write_register(DRIVER_2_CS, AW_PAGE_FUNCTION, AW_REG_GLOBALCURRENT, AW_GLOBAL_CURRENT_MAX); +#endif + AW20216_init_scaling(); + AW20216_soft_enable(); + return; +} + +void AW20216_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) { + g_pwm_buffer[index].r = red; + g_pwm_buffer[index].g = green; + g_pwm_buffer[index].b = blue; + g_pwm_buffer_update_required[index] = true; + return; +} +void AW20216_set_color_all(uint8_t red, uint8_t green, uint8_t blue) { + for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { + AW20216_set_color(i, red, green, blue); + } + return; +} +void AW20216_update_pwm_buffers(void) { + for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { + if (g_pwm_buffer_update_required[i]) { + AW20216_update_pwm(i, g_pwm_buffer[i].r, g_pwm_buffer[i].g, g_pwm_buffer[i].b); + g_pwm_buffer_update_required[i] = false; + } + } + return; +} diff --git a/drivers/awinic/aw20216.h b/drivers/awinic/aw20216.h new file mode 100644 index 0000000000..9c6865cc82 --- /dev/null +++ b/drivers/awinic/aw20216.h @@ -0,0 +1,251 @@ +/* Copyright 2021 Jasper Chan (Gigahawk) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#pragma once + +#include <stdint.h> +#include <stdbool.h> + +typedef struct aw_led { + uint8_t driver : 2; + uint8_t r; + uint8_t g; + uint8_t b; +} aw_led; + +extern const aw_led g_aw_leds[DRIVER_LED_TOTAL]; + +void AW20216_init(void); +void AW20216_set_color(int index, uint8_t red, uint8_t green, uint8_t blue); +void AW20216_set_color_all(uint8_t red, uint8_t green, uint8_t blue); +void AW20216_update_pwm_buffers(void); + +#define CS1_SW1 0x00 +#define CS2_SW1 0x01 +#define CS3_SW1 0x02 +#define CS4_SW1 0x03 +#define CS5_SW1 0x04 +#define CS6_SW1 0x05 +#define CS7_SW1 0x06 +#define CS8_SW1 0x07 +#define CS9_SW1 0x08 +#define CS10_SW1 0x09 +#define CS11_SW1 0x0A +#define CS12_SW1 0x0B +#define CS13_SW1 0x0C +#define CS14_SW1 0x0D +#define CS15_SW1 0x0E +#define CS16_SW1 0x0F +#define CS17_SW1 0x10 +#define CS18_SW1 0x11 +#define CS1_SW2 0x12 +#define CS2_SW2 0x13 +#define CS3_SW2 0x14 +#define CS4_SW2 0x15 +#define CS5_SW2 0x16 +#define CS6_SW2 0x17 +#define CS7_SW2 0x18 +#define CS8_SW2 0x19 +#define CS9_SW2 0x1A +#define CS10_SW2 0x1B +#define CS11_SW2 0x1C +#define CS12_SW2 0x1D +#define CS13_SW2 0x1E +#define CS14_SW2 0x1F +#define CS15_SW2 0x20 +#define CS16_SW2 0x21 +#define CS17_SW2 0x22 +#define CS18_SW2 0x23 +#define CS1_SW3 0x24 +#define CS2_SW3 0x25 +#define CS3_SW3 0x26 +#define CS4_SW3 0x27 +#define CS5_SW3 0x28 +#define CS6_SW3 0x29 +#define CS7_SW3 0x2A +#define CS8_SW3 0x2B +#define CS9_SW3 0x2C +#define CS10_SW3 0x2D +#define CS11_SW3 0x2E +#define CS12_SW3 0x2F +#define CS13_SW3 0x30 +#define CS14_SW3 0x31 +#define CS15_SW3 0x32 +#define CS16_SW3 0x33 +#define CS17_SW3 0x34 +#define CS18_SW3 0x35 +#define CS1_SW4 0x36 +#define CS2_SW4 0x37 +#define CS3_SW4 0x38 +#define CS4_SW4 0x39 +#define CS5_SW4 0x3A +#define CS6_SW4 0x3B +#define CS7_SW4 0x3C +#define CS8_SW4 0x3D +#define CS9_SW4 0x3E +#define CS10_SW4 0x3F +#define CS11_SW4 0x40 +#define CS12_SW4 0x41 +#define CS13_SW4 0x42 +#define CS14_SW4 0x43 +#define CS15_SW4 0x44 +#define CS16_SW4 0x45 +#define CS17_SW4 0x46 +#define CS18_SW4 0x47 +#define CS1_SW5 0x48 +#define CS2_SW5 0x49 +#define CS3_SW5 0x4A +#define CS4_SW5 0x4B +#define CS5_SW5 0x4C +#define CS6_SW5 0x4D +#define CS7_SW5 0x4E +#define CS8_SW5 0x4F +#define CS9_SW5 0x50 +#define CS10_SW5 0x51 +#define CS11_SW5 0x52 +#define CS12_SW5 0x53 +#define CS13_SW5 0x54 +#define CS14_SW5 0x55 +#define CS15_SW5 0x56 +#define CS16_SW5 0x57 +#define CS17_SW5 0x58 +#define CS18_SW5 0x59 +#define CS1_SW6 0x5A +#define CS2_SW6 0x5B +#define CS3_SW6 0x5C +#define CS4_SW6 0x5D +#define CS5_SW6 0x5E +#define CS6_SW6 0x5F +#define CS7_SW6 0x60 +#define CS8_SW6 0x61 +#define CS9_SW6 0x62 +#define CS10_SW6 0x63 +#define CS11_SW6 0x64 +#define CS12_SW6 0x65 +#define CS13_SW6 0x66 +#define CS14_SW6 0x67 +#define CS15_SW6 0x68 +#define CS16_SW6 0x69 +#define CS17_SW6 0x6A +#define CS18_SW6 0x6B +#define CS1_SW7 0x6C +#define CS2_SW7 0x6D +#define CS3_SW7 0x6E +#define CS4_SW7 0x6F +#define CS5_SW7 0x70 +#define CS6_SW7 0x71 +#define CS7_SW7 0x72 +#define CS8_SW7 0x73 +#define CS9_SW7 0x74 +#define CS10_SW7 0x75 +#define CS11_SW7 0x76 +#define CS12_SW7 0x77 +#define CS13_SW7 0x78 +#define CS14_SW7 0x79 +#define CS15_SW7 0x7A +#define CS16_SW7 0x7B +#define CS17_SW7 0x7C +#define CS18_SW7 0x7D +#define CS1_SW8 0x7E +#define CS2_SW8 0x7F +#define CS3_SW8 0x80 +#define CS4_SW8 0x81 +#define CS5_SW8 0x82 +#define CS6_SW8 0x83 +#define CS7_SW8 0x84 +#define CS8_SW8 0x85 +#define CS9_SW8 0x86 +#define CS10_SW8 0x87 +#define CS11_SW8 0x88 +#define CS12_SW8 0x89 +#define CS13_SW8 0x8A +#define CS14_SW8 0x8B +#define CS15_SW8 0x8C +#define CS16_SW8 0x8D +#define CS17_SW8 0x8E +#define CS18_SW8 0x8F +#define CS1_SW9 0x90 +#define CS2_SW9 0x91 +#define CS3_SW9 0x92 +#define CS4_SW9 0x93 +#define CS5_SW9 0x94 +#define CS6_SW9 0x95 +#define CS7_SW9 0x96 +#define CS8_SW9 0x97 +#define CS9_SW9 0x98 +#define CS10_SW9 0x99 +#define CS11_SW9 0x9A +#define CS12_SW9 0x9B +#define CS13_SW9 0x9C +#define CS14_SW9 0x9D +#define CS15_SW9 0x9E +#define CS16_SW9 0x9F +#define CS17_SW9 0xA0 +#define CS18_SW9 0xA1 +#define CS1_SW10 0xA2 +#define CS2_SW10 0xA3 +#define CS3_SW10 0xA4 +#define CS4_SW10 0xA5 +#define CS5_SW10 0xA6 +#define CS6_SW10 0xA7 +#define CS7_SW10 0xA8 +#define CS8_SW10 0xA9 +#define CS9_SW10 0xAA +#define CS10_SW10 0xAB +#define CS11_SW10 0xAC +#define CS12_SW10 0xAD +#define CS13_SW10 0xAE +#define CS14_SW10 0xAF +#define CS15_SW10 0xB0 +#define CS16_SW10 0xB1 +#define CS17_SW10 0xB2 +#define CS18_SW10 0xB3 +#define CS1_SW11 0xB4 +#define CS2_SW11 0xB5 +#define CS3_SW11 0xB6 +#define CS4_SW11 0xB7 +#define CS5_SW11 0xB8 +#define CS6_SW11 0xB9 +#define CS7_SW11 0xBA +#define CS8_SW11 0xBB +#define CS9_SW11 0xBC +#define CS10_SW11 0xBD +#define CS11_SW11 0xBE +#define CS12_SW11 0xBF +#define CS13_SW11 0xC0 +#define CS14_SW11 0xC1 +#define CS15_SW11 0xC2 +#define CS16_SW11 0xC3 +#define CS17_SW11 0xC4 +#define CS18_SW11 0xC5 +#define CS1_SW12 0xC6 +#define CS2_SW12 0xC7 +#define CS3_SW12 0xC8 +#define CS4_SW12 0xC9 +#define CS5_SW12 0xCA +#define CS6_SW12 0xCB +#define CS7_SW12 0xCC +#define CS8_SW12 0xCD +#define CS9_SW12 0xCE +#define CS10_SW12 0xCF +#define CS11_SW12 0xD0 +#define CS12_SW12 0xD1 +#define CS13_SW12 0xD2 +#define CS14_SW12 0xD3 +#define CS15_SW12 0xD4 +#define CS16_SW12 0xD5 +#define CS17_SW12 0xD6 +#define CS18_SW12 0xD7 diff --git a/drivers/chibios/spi_master.c b/drivers/chibios/spi_master.c index 4852a6eba4..28ddcbb2ba 100644 --- a/drivers/chibios/spi_master.c +++ b/drivers/chibios/spi_master.c @@ -18,8 +18,13 @@ #include "timer.h" -static pin_t currentSlavePin = NO_PIN; -static SPIConfig spiConfig = {false, NULL, 0, 0, 0, 0}; +static pin_t currentSlavePin = NO_PIN; + +#if defined(K20x) || defined(KL2x) +static SPIConfig spiConfig = {NULL, 0, 0, 0}; +#else +static SPIConfig spiConfig = {false, NULL, 0, 0, 0, 0}; +#endif __attribute__((weak)) void spi_init(void) { static bool is_initialised = false; @@ -27,15 +32,15 @@ __attribute__((weak)) void spi_init(void) { is_initialised = true; // Try releasing special pins for a short time - palSetPadMode(PAL_PORT(SPI_SCK_PIN), PAL_PAD(SPI_SCK_PIN), PAL_MODE_INPUT); - palSetPadMode(PAL_PORT(SPI_MOSI_PIN), PAL_PAD(SPI_MOSI_PIN), PAL_MODE_INPUT); - palSetPadMode(PAL_PORT(SPI_MISO_PIN), PAL_PAD(SPI_MISO_PIN), PAL_MODE_INPUT); + setPinInput(SPI_SCK_PIN); + setPinInput(SPI_MOSI_PIN); + setPinInput(SPI_MISO_PIN); chThdSleepMilliseconds(10); #if defined(USE_GPIOV1) - palSetPadMode(PAL_PORT(SPI_SCK_PIN), PAL_PAD(SPI_SCK_PIN), PAL_MODE_STM32_ALTERNATE_PUSHPULL); - palSetPadMode(PAL_PORT(SPI_MOSI_PIN), PAL_PAD(SPI_MOSI_PIN), PAL_MODE_STM32_ALTERNATE_PUSHPULL); - palSetPadMode(PAL_PORT(SPI_MISO_PIN), PAL_PAD(SPI_MISO_PIN), PAL_MODE_STM32_ALTERNATE_PUSHPULL); + palSetPadMode(PAL_PORT(SPI_SCK_PIN), PAL_PAD(SPI_SCK_PIN), SPI_SCK_PAL_MODE); + palSetPadMode(PAL_PORT(SPI_MOSI_PIN), PAL_PAD(SPI_MOSI_PIN), SPI_MOSI_PAL_MODE); + palSetPadMode(PAL_PORT(SPI_MISO_PIN), PAL_PAD(SPI_MISO_PIN), SPI_MISO_PAL_MODE); #else palSetPadMode(PAL_PORT(SPI_SCK_PIN), PAL_PAD(SPI_SCK_PIN), PAL_MODE_ALTERNATE(SPI_SCK_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); palSetPadMode(PAL_PORT(SPI_MOSI_PIN), PAL_PAD(SPI_MOSI_PIN), PAL_MODE_ALTERNATE(SPI_MOSI_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST); @@ -58,6 +63,54 @@ bool spi_start(pin_t slavePin, bool lsbFirst, uint8_t mode, uint16_t divisor) { return false; } +#if defined(K20x) || defined(KL2x) + spiConfig.tar0 = SPIx_CTARn_FMSZ(7) | SPIx_CTARn_ASC(1); + + if (lsbFirst) { + spiConfig.tar0 |= SPIx_CTARn_LSBFE; + } + + switch (mode) { + case 0: + break; + case 1: + spiConfig.tar0 |= SPIx_CTARn_CPHA; + break; + case 2: + spiConfig.tar0 |= SPIx_CTARn_CPOL; + break; + case 3: + spiConfig.tar0 |= SPIx_CTARn_CPHA | SPIx_CTARn_CPOL; + break; + } + + switch (roundedDivisor) { + case 2: + spiConfig.tar0 |= SPIx_CTARn_BR(0); + break; + case 4: + spiConfig.tar0 |= SPIx_CTARn_BR(1); + break; + case 8: + spiConfig.tar0 |= SPIx_CTARn_BR(3); + break; + case 16: + spiConfig.tar0 |= SPIx_CTARn_BR(4); + break; + case 32: + spiConfig.tar0 |= SPIx_CTARn_BR(5); + break; + case 64: + spiConfig.tar0 |= SPIx_CTARn_BR(6); + break; + case 128: + spiConfig.tar0 |= SPIx_CTARn_BR(7); + break; + case 256: + spiConfig.tar0 |= SPIx_CTARn_BR(8); + break; + } +#else spiConfig.cr1 = 0; if (lsbFirst) { @@ -103,6 +156,7 @@ bool spi_start(pin_t slavePin, bool lsbFirst, uint8_t mode, uint16_t divisor) { spiConfig.cr1 |= SPI_CR1_BR_2 | SPI_CR1_BR_1 | SPI_CR1_BR_0; break; } +#endif currentSlavePin = slavePin; spiConfig.ssport = PAL_PORT(slavePin); diff --git a/drivers/chibios/spi_master.h b/drivers/chibios/spi_master.h index e93580e319..b5a6ef1437 100644 --- a/drivers/chibios/spi_master.h +++ b/drivers/chibios/spi_master.h @@ -21,6 +21,7 @@ #include <stdbool.h> #include "gpio.h" +#include "chibios_config.h" #ifndef SPI_DRIVER # define SPI_DRIVER SPID2 @@ -31,7 +32,11 @@ #endif #ifndef SPI_SCK_PAL_MODE -# define SPI_SCK_PAL_MODE 5 +# if defined(USE_GPIOV1) +# define SPI_SCK_PAL_MODE PAL_MODE_STM32_ALTERNATE_PUSHPULL +# else +# define SPI_SCK_PAL_MODE 5 +# endif #endif #ifndef SPI_MOSI_PIN @@ -39,7 +44,11 @@ #endif #ifndef SPI_MOSI_PAL_MODE -# define SPI_MOSI_PAL_MODE 5 +# if defined(USE_GPIOV1) +# define SPI_MOSI_PAL_MODE PAL_MODE_STM32_ALTERNATE_PUSHPULL +# else +# define SPI_MOSI_PAL_MODE 5 +# endif #endif #ifndef SPI_MISO_PIN @@ -47,7 +56,11 @@ #endif #ifndef SPI_MISO_PAL_MODE -# define SPI_MISO_PAL_MODE 5 +# if defined(USE_GPIOV1) +# define SPI_MISO_PAL_MODE PAL_MODE_STM32_ALTERNATE_PUSHPULL +# else +# define SPI_MISO_PAL_MODE 5 +# endif #endif typedef int16_t spi_status_t; diff --git a/drivers/lcd/st7565.c b/drivers/lcd/st7565.c new file mode 100644 index 0000000000..4b4891ce71 --- /dev/null +++ b/drivers/lcd/st7565.c @@ -0,0 +1,479 @@ +/* +Copyright 2021 + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include "st7565.h" + +#include <string.h> + +#include "keyboard.h" +#include "progmem.h" +#include "timer.h" +#include "wait.h" + +#include ST7565_FONT_H + +// Fundamental Commands +#define CONTRAST 0x81 +#define DISPLAY_ALL_ON 0xA5 +#define DISPLAY_ALL_ON_RESUME 0xA4 +#define NORMAL_DISPLAY 0xA6 +#define DISPLAY_ON 0xAF +#define DISPLAY_OFF 0xAE +#define NOP 0xE3 + +// Addressing Setting Commands +#define PAM_SETCOLUMN_LSB 0x00 +#define PAM_SETCOLUMN_MSB 0x10 +#define PAM_PAGE_ADDR 0xB0 // 0xb0 -- 0xb7 + +// Hardware Configuration Commands +#define DISPLAY_START_LINE 0x40 +#define SEGMENT_REMAP 0xA0 +#define SEGMENT_REMAP_INV 0xA1 +#define COM_SCAN_INC 0xC0 +#define COM_SCAN_DEC 0xC8 +#define LCD_BIAS_7 0xA3 +#define LCD_BIAS_9 0xA2 +#define RESISTOR_RATIO 0x20 +#define POWER_CONTROL 0x28 + +// Misc defines +#ifndef ST7565_BLOCK_COUNT +# define ST7565_BLOCK_COUNT (sizeof(ST7565_BLOCK_TYPE) * 8) +#endif +#ifndef ST7565_BLOCK_SIZE +# define ST7565_BLOCK_SIZE (ST7565_MATRIX_SIZE / ST7565_BLOCK_COUNT) +#endif + +#define ST7565_ALL_BLOCKS_MASK (((((ST7565_BLOCK_TYPE)1 << (ST7565_BLOCK_COUNT - 1)) - 1) << 1) | 1) + +#define HAS_FLAGS(bits, flags) ((bits & flags) == flags) + +// Display buffer's is the same as the display memory layout +// this is so we don't end up with rounding errors with +// parts of the display unusable or don't get cleared correctly +// and also allows for drawing & inverting +uint8_t st7565_buffer[ST7565_MATRIX_SIZE]; +uint8_t * st7565_cursor; +ST7565_BLOCK_TYPE st7565_dirty = 0; +bool st7565_initialized = false; +bool st7565_active = false; +display_rotation_t st7565_rotation = DISPLAY_ROTATION_0; +#if ST7565_TIMEOUT > 0 +uint32_t st7565_timeout; +#endif +#if ST7565_UPDATE_INTERVAL > 0 +uint16_t st7565_update_timeout; +#endif + +// Flips the rendering bits for a character at the current cursor position +static void InvertCharacter(uint8_t *cursor) { + const uint8_t *end = cursor + ST7565_FONT_WIDTH; + while (cursor < end) { + *cursor = ~(*cursor); + cursor++; + } +} + +bool st7565_init(display_rotation_t rotation) { + setPinOutput(ST7565_A0_PIN); + writePinHigh(ST7565_A0_PIN); + setPinOutput(ST7565_RST_PIN); + writePinHigh(ST7565_RST_PIN); + + st7565_rotation = st7565_init_user(rotation); + + spi_init(); + spi_start(ST7565_SS_PIN, false, 0, ST7565_SPI_CLK_DIVISOR); + + st7565_reset(); + + st7565_send_cmd(LCD_BIAS_7); + if (!HAS_FLAGS(st7565_rotation, DISPLAY_ROTATION_180)) { + st7565_send_cmd(SEGMENT_REMAP); + st7565_send_cmd(COM_SCAN_DEC); + } else { + st7565_send_cmd(SEGMENT_REMAP_INV); + st7565_send_cmd(COM_SCAN_INC); + } + st7565_send_cmd(DISPLAY_START_LINE | 0x00); + st7565_send_cmd(CONTRAST); + st7565_send_cmd(ST7565_CONTRAST); + st7565_send_cmd(RESISTOR_RATIO | 0x01); + st7565_send_cmd(POWER_CONTROL | 0x04); + wait_ms(50); + st7565_send_cmd(POWER_CONTROL | 0x06); + wait_ms(50); + st7565_send_cmd(POWER_CONTROL | 0x07); + wait_ms(10); + st7565_send_cmd(DISPLAY_ON); + st7565_send_cmd(DISPLAY_ALL_ON_RESUME); + st7565_send_cmd(NORMAL_DISPLAY); + + spi_stop(); + +#if ST7565_TIMEOUT > 0 + st7565_timeout = timer_read32() + ST7565_TIMEOUT; +#endif + + st7565_clear(); + st7565_initialized = true; + st7565_active = true; + return true; +} + +__attribute__((weak)) display_rotation_t st7565_init_user(display_rotation_t rotation) { return rotation; } + +void st7565_clear(void) { + memset(st7565_buffer, 0, sizeof(st7565_buffer)); + st7565_cursor = &st7565_buffer[0]; + st7565_dirty = ST7565_ALL_BLOCKS_MASK; +} + +uint8_t crot(uint8_t a, int8_t n) { + const uint8_t mask = 0x7; + n &= mask; + return a << n | a >> (-n & mask); +} + +void st7565_render(void) { + if (!st7565_initialized) { + return; + } + + // Do we have work to do? + st7565_dirty &= ST7565_ALL_BLOCKS_MASK; + if (!st7565_dirty) { + return; + } + + // Find first dirty block + uint8_t update_start = 0; + while (!(st7565_dirty & ((ST7565_BLOCK_TYPE)1 << update_start))) { + ++update_start; + } + + // Calculate commands to set memory addressing bounds. + uint8_t start_page = ST7565_BLOCK_SIZE * update_start / ST7565_DISPLAY_WIDTH; + uint8_t start_column = ST7565_BLOCK_SIZE * update_start % ST7565_DISPLAY_WIDTH; + // IC has 132 segment drivers, for panels with less width we need to offset the starting column + if (HAS_FLAGS(st7565_rotation, DISPLAY_ROTATION_180)) { + start_column += (132 - ST7565_DISPLAY_WIDTH); + } + + spi_start(ST7565_SS_PIN, false, 0, ST7565_SPI_CLK_DIVISOR); + + st7565_send_cmd(PAM_PAGE_ADDR | start_page); + st7565_send_cmd(PAM_SETCOLUMN_LSB | ((ST7565_COLUMN_OFFSET + start_column) & 0x0f)); + st7565_send_cmd(PAM_SETCOLUMN_MSB | ((ST7565_COLUMN_OFFSET + start_column) >> 4 & 0x0f)); + + st7565_send_data(&st7565_buffer[ST7565_BLOCK_SIZE * update_start], ST7565_BLOCK_SIZE); + + // Turn on display if it is off + st7565_on(); + + // Clear dirty flag + st7565_dirty &= ~((ST7565_BLOCK_TYPE)1 << update_start); +} + +void st7565_set_cursor(uint8_t col, uint8_t line) { + uint16_t index = line * ST7565_DISPLAY_WIDTH + col * ST7565_FONT_WIDTH; + + // Out of bounds? + if (index >= ST7565_MATRIX_SIZE) { + index = 0; + } + + st7565_cursor = &st7565_buffer[index]; +} + +void st7565_advance_page(bool clearPageRemainder) { + uint16_t index = st7565_cursor - &st7565_buffer[0]; + uint8_t remaining = ST7565_DISPLAY_WIDTH - (index % ST7565_DISPLAY_WIDTH); + + if (clearPageRemainder) { + // Remaining Char count + remaining = remaining / ST7565_FONT_WIDTH; + + // Write empty character until next line + while (remaining--) st7565_write_char(' ', false); + } else { + // Next page index out of bounds? + if (index + remaining >= ST7565_MATRIX_SIZE) { + index = 0; + remaining = 0; + } + + st7565_cursor = &st7565_buffer[index + remaining]; + } +} + +void st7565_advance_char(void) { + uint16_t nextIndex = st7565_cursor - &st7565_buffer[0] + ST7565_FONT_WIDTH; + uint8_t remainingSpace = ST7565_DISPLAY_WIDTH - (nextIndex % ST7565_DISPLAY_WIDTH); + + // Do we have enough space on the current line for the next character + if (remainingSpace < ST7565_FONT_WIDTH) { + nextIndex += remainingSpace; + } + + // Did we go out of bounds + if (nextIndex >= ST7565_MATRIX_SIZE) { + nextIndex = 0; + } + + // Update cursor position + st7565_cursor = &st7565_buffer[nextIndex]; +} + +// Main handler that writes character data to the display buffer +void st7565_write_char(const char data, bool invert) { + // Advance to the next line if newline + if (data == '\n') { + // Old source wrote ' ' until end of line... + st7565_advance_page(true); + return; + } + + if (data == '\r') { + st7565_advance_page(false); + return; + } + + // copy the current render buffer to check for dirty after + static uint8_t st7565_temp_buffer[ST7565_FONT_WIDTH]; + memcpy(&st7565_temp_buffer, st7565_cursor, ST7565_FONT_WIDTH); + + _Static_assert(sizeof(font) >= ((ST7565_FONT_END + 1 - ST7565_FONT_START) * ST7565_FONT_WIDTH), "ST7565_FONT_END references outside array"); + + // set the reder buffer data + uint8_t cast_data = (uint8_t)data; // font based on unsigned type for index + if (cast_data < ST7565_FONT_START || cast_data > ST7565_FONT_END) { + memset(st7565_cursor, 0x00, ST7565_FONT_WIDTH); + } else { + const uint8_t *glyph = &font[(cast_data - ST7565_FONT_START) * ST7565_FONT_WIDTH]; + memcpy_P(st7565_cursor, glyph, ST7565_FONT_WIDTH); + } + + // Invert if needed + if (invert) { + InvertCharacter(st7565_cursor); + } + + // Dirty check + if (memcmp(&st7565_temp_buffer, st7565_cursor, ST7565_FONT_WIDTH)) { + uint16_t index = st7565_cursor - &st7565_buffer[0]; + st7565_dirty |= ((ST7565_BLOCK_TYPE)1 << (index / ST7565_BLOCK_SIZE)); + // Edgecase check if the written data spans the 2 chunks + st7565_dirty |= ((ST7565_BLOCK_TYPE)1 << ((index + ST7565_FONT_WIDTH - 1) / ST7565_BLOCK_SIZE)); + } + + // Finally move to the next char + st7565_advance_char(); +} + +void st7565_write(const char *data, bool invert) { + const char *end = data + strlen(data); + while (data < end) { + st7565_write_char(*data, invert); + data++; + } +} + +void st7565_write_ln(const char *data, bool invert) { + st7565_write(data, invert); + st7565_advance_page(true); +} + +void st7565_pan(bool left) { + uint16_t i = 0; + for (uint16_t y = 0; y < ST7565_DISPLAY_HEIGHT / 8; y++) { + if (left) { + for (uint16_t x = 0; x < ST7565_DISPLAY_WIDTH - 1; x++) { + i = y * ST7565_DISPLAY_WIDTH + x; + st7565_buffer[i] = st7565_buffer[i + 1]; + } + } else { + for (uint16_t x = ST7565_DISPLAY_WIDTH - 1; x > 0; x--) { + i = y * ST7565_DISPLAY_WIDTH + x; + st7565_buffer[i] = st7565_buffer[i - 1]; + } + } + } + st7565_dirty = ST7565_ALL_BLOCKS_MASK; +} + +display_buffer_reader_t st7565_read_raw(uint16_t start_index) { + if (start_index > ST7565_MATRIX_SIZE) start_index = ST7565_MATRIX_SIZE; + display_buffer_reader_t ret_reader; + ret_reader.current_element = &st7565_buffer[start_index]; + ret_reader.remaining_element_count = ST7565_MATRIX_SIZE - start_index; + return ret_reader; +} + +void st7565_write_raw_byte(const char data, uint16_t index) { + if (index > ST7565_MATRIX_SIZE) index = ST7565_MATRIX_SIZE; + if (st7565_buffer[index] == data) return; + st7565_buffer[index] = data; + st7565_dirty |= ((ST7565_BLOCK_TYPE)1 << (index / ST7565_BLOCK_SIZE)); +} + +void st7565_write_raw(const char *data, uint16_t size) { + uint16_t cursor_start_index = st7565_cursor - &st7565_buffer[0]; + if ((size + cursor_start_index) > ST7565_MATRIX_SIZE) size = ST7565_MATRIX_SIZE - cursor_start_index; + for (uint16_t i = cursor_start_index; i < cursor_start_index + size; i++) { + if (st7565_buffer[i] == data[i]) continue; + st7565_buffer[i] = data[i]; + st7565_dirty |= ((ST7565_BLOCK_TYPE)1 << (i / ST7565_BLOCK_SIZE)); + } +} + +void st7565_write_pixel(uint8_t x, uint8_t y, bool on) { + if (x >= ST7565_DISPLAY_WIDTH) { + return; + } + uint16_t index = x + (y / 8) * ST7565_DISPLAY_WIDTH; + if (index >= ST7565_MATRIX_SIZE) { + return; + } + uint8_t data = st7565_buffer[index]; + if (on) { + data |= (1 << (y % 8)); + } else { + data &= ~(1 << (y % 8)); + } + if (st7565_buffer[index] != data) { + st7565_buffer[index] = data; + st7565_dirty |= ((ST7565_BLOCK_TYPE)1 << (index / ST7565_BLOCK_SIZE)); + } +} + +#if defined(__AVR__) +void st7565_write_P(const char *data, bool invert) { + uint8_t c = pgm_read_byte(data); + while (c != 0) { + st7565_write_char(c, invert); + c = pgm_read_byte(++data); + } +} + +void st7565_write_ln_P(const char *data, bool invert) { + st7565_write_P(data, invert); + st7565_advance_page(true); +} + +void st7565_write_raw_P(const char *data, uint16_t size) { + uint16_t cursor_start_index = st7565_cursor - &st7565_buffer[0]; + if ((size + cursor_start_index) > ST7565_MATRIX_SIZE) size = ST7565_MATRIX_SIZE - cursor_start_index; + for (uint16_t i = cursor_start_index; i < cursor_start_index + size; i++) { + uint8_t c = pgm_read_byte(data++); + if (st7565_buffer[i] == c) continue; + st7565_buffer[i] = c; + st7565_dirty |= ((ST7565_BLOCK_TYPE)1 << (i / ST7565_BLOCK_SIZE)); + } +} +#endif // defined(__AVR__) + +bool st7565_on(void) { + if (!st7565_initialized) { + return st7565_active; + } + +#if ST7565_TIMEOUT > 0 + st7565_timeout = timer_read32() + ST7565_TIMEOUT; +#endif + + if (!st7565_active) { + spi_start(ST7565_SS_PIN, false, 0, ST7565_SPI_CLK_DIVISOR); + st7565_send_cmd(DISPLAY_ON); + spi_stop(); + st7565_active = true; + st7565_on_user(); + } + return st7565_active; +} + +__attribute__((weak)) void st7565_on_user(void) {} + +bool st7565_off(void) { + if (!st7565_initialized) { + return !st7565_active; + } + + if (st7565_active) { + spi_start(ST7565_SS_PIN, false, 0, ST7565_SPI_CLK_DIVISOR); + st7565_send_cmd(DISPLAY_OFF); + spi_stop(); + st7565_active = false; + st7565_off_user(); + } + return !st7565_active; +} + +__attribute__((weak)) void st7565_off_user(void) {} + +bool st7565_is_on(void) { return st7565_active; } + +uint8_t st7565_max_chars(void) { return ST7565_DISPLAY_WIDTH / ST7565_FONT_WIDTH; } + +uint8_t st7565_max_lines(void) { return ST7565_DISPLAY_HEIGHT / ST7565_FONT_HEIGHT; } + +void st7565_task(void) { + if (!st7565_initialized) { + return; + } + +#if ST7565_UPDATE_INTERVAL > 0 + if (timer_elapsed(st7565_update_timeout) >= ST7565_UPDATE_INTERVAL) { + st7565_update_timeout = timer_read(); + st7565_set_cursor(0, 0); + st7565_task_user(); + } +#else + st7565_set_cursor(0, 0); + st7565_task_user(); +#endif + + // Smart render system, no need to check for dirty + st7565_render(); + + // Display timeout check +#if ST7565_TIMEOUT > 0 + if (st7565_active && timer_expired32(timer_read32(), st7565_timeout)) { + st7565_off(); + } +#endif +} + +__attribute__((weak)) void st7565_task_user(void) {} + +void st7565_reset(void) { + writePinLow(ST7565_RST_PIN); + wait_ms(20); + writePinHigh(ST7565_RST_PIN); + wait_ms(20); +} + +spi_status_t st7565_send_cmd(uint8_t cmd) { + writePinLow(ST7565_A0_PIN); + return spi_write(cmd); +} + +spi_status_t st7565_send_data(uint8_t *data, uint16_t length) { + writePinHigh(ST7565_A0_PIN); + return spi_transmit(data, length); +} diff --git a/drivers/lcd/st7565.h b/drivers/lcd/st7565.h new file mode 100644 index 0000000000..53cfc9a810 --- /dev/null +++ b/drivers/lcd/st7565.h @@ -0,0 +1,215 @@ +/* +Copyright 2021 + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#pragma once + +#include <stdint.h> +#include <stdbool.h> + +#include "spi_master.h" + +#ifndef ST7565_DISPLAY_WIDTH +# define ST7565_DISPLAY_WIDTH 128 +#endif +#ifndef ST7565_DISPLAY_HEIGHT +# define ST7565_DISPLAY_HEIGHT 32 +#endif +#ifndef ST7565_MATRIX_SIZE +# define ST7565_MATRIX_SIZE (ST7565_DISPLAY_HEIGHT / 8 * ST7565_DISPLAY_WIDTH) // 1024 (compile time mathed) +#endif +#ifndef ST7565_BLOCK_TYPE +# define ST7565_BLOCK_TYPE uint16_t +#endif +#ifndef ST7565_BLOCK_COUNT +# define ST7565_BLOCK_COUNT (sizeof(ST7565_BLOCK_TYPE) * 8) // 32 (compile time mathed) +#endif +#ifndef ST7565_BLOCK_SIZE +# define ST7565_BLOCK_SIZE (ST7565_MATRIX_SIZE / ST7565_BLOCK_COUNT) // 32 (compile time mathed) +#endif + +// the column address corresponding to the first column in the display hardware +#if !defined(ST7565_COLUMN_OFFSET) +# define ST7565_COLUMN_OFFSET 0 +#endif + +// spi clock divisor +#if !defined(ST7565_SPI_CLK_DIVISOR) +# define ST7565_SPI_CLK_DIVISOR 4 +#endif + +// Custom font file to use +#if !defined(ST7565_FONT_H) +# define ST7565_FONT_H "glcdfont.c" +#endif +// unsigned char value of the first character in the font file +#if !defined(ST7565_FONT_START) +# define ST7565_FONT_START 0 +#endif +// unsigned char value of the last character in the font file +#if !defined(ST7565_FONT_END) +# define ST7565_FONT_END 223 +#endif +// Font render width +#if !defined(ST7565_FONT_WIDTH) +# define ST7565_FONT_WIDTH 6 +#endif +// Font render height +#if !defined(ST7565_FONT_HEIGHT) +# define ST7565_FONT_HEIGHT 8 +#endif +// Default contrast level +#if !defined(ST7565_CONTRAST) +# define ST7565_CONTRAST 32 +#endif + +#if !defined(ST7565_TIMEOUT) +# if defined(ST7565_DISABLE_TIMEOUT) +# define ST7565_TIMEOUT 0 +# else +# define ST7565_TIMEOUT 60000 +# endif +#endif + +#if !defined(ST7565_UPDATE_INTERVAL) && defined(SPLIT_KEYBOARD) +# define ST7565_UPDATE_INTERVAL 50 +#endif + +typedef struct __attribute__((__packed__)) { + uint8_t *current_element; + uint16_t remaining_element_count; +} display_buffer_reader_t; + +// Rotation enum values are flags +typedef enum { DISPLAY_ROTATION_0, DISPLAY_ROTATION_180 } display_rotation_t; + +// Initialize the display, rotating the rendered output based on the define passed in. +// Returns true if the display was initialized successfully +bool st7565_init(display_rotation_t rotation); + +// Called at the start of st7565_init, weak function overridable by the user +// rotation - the value passed into st7565_init +// Return new display_rotation_t if you want to override default rotation +display_rotation_t st7565_init_user(display_rotation_t rotation); + +// Clears the display buffer, resets cursor position to 0, and sets the buffer to dirty for rendering +void st7565_clear(void); + +// Renders the dirty chunks of the buffer to display +void st7565_render(void); + +// Moves cursor to character position indicated by column and line, wraps if out of bounds +// Max column denoted by 'st7565_max_chars()' and max lines by 'st7565_max_lines()' functions +void st7565_set_cursor(uint8_t col, uint8_t line); + +// Advances the cursor to the next page, writing ' ' if true +// Wraps to the begining when out of bounds +void st7565_advance_page(bool clearPageRemainder); + +// Moves the cursor forward 1 character length +// Advance page if there is not enough room for the next character +// Wraps to the begining when out of bounds +void st7565_advance_char(void); + +// Writes a single character to the buffer at current cursor position +// Advances the cursor while writing, inverts the pixels if true +// Main handler that writes character data to the display buffer +void st7565_write_char(const char data, bool invert); + +// Writes a string to the buffer at current cursor position +// Advances the cursor while writing, inverts the pixels if true +void st7565_write(const char *data, bool invert); + +// Writes a string to the buffer at current cursor position +// Advances the cursor while writing, inverts the pixels if true +// Advances the cursor to the next page, wiring ' ' to the remainder of the current page +void st7565_write_ln(const char *data, bool invert); + +// Pans the buffer to the right (or left by passing true) by moving contents of the buffer +// Useful for moving the screen in preparation for new drawing +void st7565_pan(bool left); + +// Returns a pointer to the requested start index in the buffer plus remaining +// buffer length as struct +display_buffer_reader_t st7565_read_raw(uint16_t start_index); + +// Writes a string to the buffer at current cursor position +void st7565_write_raw(const char *data, uint16_t size); + +// Writes a single byte into the buffer at the specified index +void st7565_write_raw_byte(const char data, uint16_t index); + +// Sets a specific pixel on or off +// Coordinates start at top-left and go right and down for positive x and y +void st7565_write_pixel(uint8_t x, uint8_t y, bool on); + +#if defined(__AVR__) +// Writes a PROGMEM string to the buffer at current cursor position +// Advances the cursor while writing, inverts the pixels if true +// Remapped to call 'void st7565_write(const char *data, bool invert);' on ARM +void st7565_write_P(const char *data, bool invert); + +// Writes a PROGMEM string to the buffer at current cursor position +// Advances the cursor while writing, inverts the pixels if true +// Advances the cursor to the next page, wiring ' ' to the remainder of the current page +// Remapped to call 'void st7565_write_ln(const char *data, bool invert);' on ARM +void st7565_write_ln_P(const char *data, bool invert); + +// Writes a PROGMEM string to the buffer at current cursor position +void st7565_write_raw_P(const char *data, uint16_t size); +#else +# define st7565_write_P(data, invert) st7565_write(data, invert) +# define st7565_write_ln_P(data, invert) st7565_write_ln(data, invert) +# define st7565_write_raw_P(data, size) st7565_write_raw(data, size) +#endif // defined(__AVR__) + +// Can be used to manually turn on the screen if it is off +// Returns true if the screen was on or turns on +bool st7565_on(void); + +// Called when st7565_on() turns on the screen, weak function overridable by the user +// Not called if the screen is already on +void st7565_on_user(void); + +// Can be used to manually turn off the screen if it is on +// Returns true if the screen was off or turns off +bool st7565_off(void); + +// Called when st7565_off() turns off the screen, weak function overridable by the user +// Not called if the screen is already off +void st7565_off_user(void); + +// Returns true if the screen is currently on, false if it is +// not +bool st7565_is_on(void); + +// Basically it's st7565_render, but with timeout management and st7565_task_user calling! +void st7565_task(void); + +// Called at the start of st7565_task, weak function overridable by the user +void st7565_task_user(void); + +// Returns the maximum number of characters that will fit on a line +uint8_t st7565_max_chars(void); + +// Returns the maximum number of lines that will fit on the display +uint8_t st7565_max_lines(void); + +void st7565_reset(void); + +spi_status_t st7565_send_cmd(uint8_t cmd); + +spi_status_t st7565_send_data(uint8_t *data, uint16_t length); |