From 32bdcfaf28122f42fd920c95778f71e5bda885d5 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Tue, 31 Oct 2023 12:30:19 +0100 Subject: [PATCH] SSD1312: Add example board file --- .../addons/gdisp/board_SSD1312_stm32cubehal.h | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 boards/addons/gdisp/board_SSD1312_stm32cubehal.h diff --git a/boards/addons/gdisp/board_SSD1312_stm32cubehal.h b/boards/addons/gdisp/board_SSD1312_stm32cubehal.h new file mode 100644 index 00000000..69cdf932 --- /dev/null +++ b/boards/addons/gdisp/board_SSD1312_stm32cubehal.h @@ -0,0 +1,92 @@ +#pragma once + +#include +#include + +// The command byte to put on the front of each page line +#define SSD1312_PAGE_PREFIX 0x40 // Co = 0, D/C = 1 + +static I2C_HandleTypeDef i2cHandle; + +static GFXINLINE void init_board(GDisplay *g) +{ + (void) g; + + // GPIO + { + GPIO_InitTypeDef GPIO_InitStruct = {0}; + + __HAL_RCC_GPIOB_CLK_ENABLE(); + + // I2C SCL + GPIO_InitStruct.Pin = GPIO_PIN_8; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_PULLUP; + GPIO_InitStruct.Speed = GPIO_SPEED_FAST; + GPIO_InitStruct.Alternate = GPIO_AF4_I2C1; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + // I2C SDA + GPIO_InitStruct.Pin = GPIO_PIN_9; + GPIO_InitStruct.Mode = GPIO_MODE_AF_OD; + GPIO_InitStruct.Pull = GPIO_PULLUP; + GPIO_InitStruct.Speed = GPIO_SPEED_FAST; + GPIO_InitStruct.Alternate = GPIO_AF4_I2C1; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + } + + // I2C1 + { + __HAL_RCC_I2C1_CLK_ENABLE(); + + i2cHandle.Instance = I2C1; + i2cHandle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; + i2cHandle.Init.ClockSpeed = 400000; + i2cHandle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; + i2cHandle.Init.DutyCycle = I2C_DUTYCYCLE_2; + i2cHandle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; + i2cHandle.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; + if (HAL_I2C_Init(&i2cHandle) != HAL_OK) + gfxHalt("I2C HAL init error"); + } +} + +static GFXINLINE void post_init_board(GDisplay *g) +{ + (void) g; +} + +static GFXINLINE void setpin_reset(GDisplay *g, gBool state) +{ + (void) g; + (void) state; +} + +static GFXINLINE void acquire_bus(GDisplay *g) +{ + (void) g; +} + +static GFXINLINE void release_bus(GDisplay *g) +{ + (void) g; +} + +static GFXINLINE void write_cmd(GDisplay *g, gU8 *data, gU16 length) +{ + (void) g; + + gU8 buf[4]; // length is always <= 3 + buf[0] = 0x00; + memcpy(buf+1, data, length); + + HAL_I2C_Master_Transmit(&i2cHandle, (0x3c << 1), buf, length+1, 10000); +} + +static GFXINLINE void write_data(GDisplay *g, gU8 *data, gU16 length) +{ + (void) g; + + HAL_I2C_Master_Transmit(&i2cHandle, (0x3c << 1), data, length, 10000); +} +