Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 2 | mjames | 1 | /* |
| 2 | * stm32_halDisplay.cpp |
||
| 3 | * |
||
| 4 | * Created on: 1 Nov 2020 |
||
| 5 | * Author: mike |
||
| 6 | */ |
||
| 7 | #include "main.h" |
||
| 8 | |||
| 9 | #include "libOLED/stm32_halDisplay.H" |
||
| 10 | |||
| 11 | stm32_halDisplay_t::stm32_halDisplay_t (int const width, int const height, |
||
| 12 | int const ramwidth, uint8_t *const data, |
||
| 13 | SPI_HandleTypeDef *const spiInterface, |
||
| 14 | GPIO_TypeDef *const CD_GPIO, |
||
| 15 | uint16_t CD_GPIO_Pin, |
||
| 16 | GPIO_TypeDef *const RESET_GPIO, |
||
| 17 | uint16_t RESET_GPIO_Pin, |
||
| 18 | GPIO_TypeDef *const NSS_GPIO, |
||
| 19 | uint16_t NSS_GPIO_Pin) : |
||
| 20 | display_t (width, height, ramwidth, data), m_spiInterface (spiInterface), m_CD_GPIO ( |
||
| 21 | CD_GPIO), m_CD_GPIO_Pin (CD_GPIO_Pin), m_RESET_GPIO (RESET_GPIO), m_RESET_GPIO_Pin ( |
||
| 22 | RESET_GPIO_Pin), m_NSS_GPIO (NSS_GPIO), m_NSS_GPIO_Pin (NSS_GPIO_Pin) |
||
| 23 | { |
||
| 24 | } |
||
| 25 | |||
| 26 | void |
||
| 27 | stm32_halDisplay_t::oledSetCD (uint8_t cd) |
||
| 28 | { |
||
| 29 | HAL_GPIO_WritePin (m_CD_GPIO, m_CD_GPIO_Pin, cd ? GPIO_PIN_SET : GPIO_PIN_RESET); |
||
| 30 | } |
||
| 31 | |||
| 32 | void |
||
| 33 | stm32_halDisplay_t::oledReset (void) |
||
| 34 | { |
||
| 35 | |||
| 36 | HAL_GPIO_WritePin (m_RESET_GPIO, m_RESET_GPIO_Pin, GPIO_PIN_SET); |
||
| 37 | // VDD (3.3V) goes high at start, lets just chill for a ms |
||
| 38 | HAL_Delay (1); |
||
| 39 | // bring reset low |
||
| 40 | HAL_GPIO_WritePin (m_RESET_GPIO, m_RESET_GPIO_Pin, GPIO_PIN_RESET); |
||
| 41 | // wait 10ms |
||
| 42 | HAL_Delay (10); |
||
| 43 | // bring out of reset |
||
| 44 | HAL_GPIO_WritePin (m_RESET_GPIO, m_RESET_GPIO_Pin, GPIO_PIN_SET); |
||
| 45 | } |
||
| 46 | |||
| 47 | void |
||
| 48 | stm32_halDisplay_t::oledWrite (uint8_t c) |
||
| 49 | { |
||
| 50 | uint8_t buffer[1]; |
||
| 51 | buffer[0] = c; |
||
| 52 | |||
| 53 | HAL_GPIO_WritePin (m_NSS_GPIO, m_NSS_GPIO_Pin, GPIO_PIN_RESET); |
||
| 54 | |||
| 55 | HAL_SPI_Transmit (m_spiInterface, buffer, 1, 2); // allow 2mS for transfer |
||
| 56 | |||
| 57 | HAL_GPIO_WritePin (m_NSS_GPIO, m_NSS_GPIO_Pin, GPIO_PIN_SET); |
||
| 58 | } |
||
| 59 | |||
| 60 | void |
||
| 61 | stm32_halDisplay_t::oledWrite (uint8_t *buffer, uint8_t len) |
||
| 62 | { |
||
| 63 | HAL_GPIO_WritePin (m_NSS_GPIO, m_NSS_GPIO_Pin, GPIO_PIN_RESET); |
||
| 64 | |||
| 65 | HAL_SPI_Transmit (m_spiInterface, buffer, len, 100); // allow 100mS for transfer |
||
| 66 | |||
| 67 | HAL_GPIO_WritePin (m_NSS_GPIO, m_NSS_GPIO_Pin, GPIO_PIN_SET); |
||
| 68 | |||
| 69 | } |
||
| 70 |