Close

SSD1351 Display and uGFX

A project log for STM32F030F4P6 breakout board

Not as bulky as the nucleo boards, after all.

christophChristoph 06/18/2015 at 21:450 Comments

This was fairly easy - I added the uGFX sources to my project and after rearranging some include directives it actually compiled fine. uGFX also comes with some pre-written display drivers, including one for the SSD1351. The only thing I had to customize was the board file template:

#include "gpio.h" // <- generated by CubeMX
#include "spi.h"// <- generated by CubeMX

#define PORT_OLED_RESET GPIOA
#define PIN_OLED_RESET GPIO_PIN_3
#define PORT_OLED_CS GPIOA
#define PIN_OLED_CS GPIO_PIN_4
#define PORT_OLED_DC GPIOB
#define PIN_OLED_DC GPIO_PIN_1

static inline void init_board(GDisplay *g) {
  (void) g;
  HAL_GPIO_WritePin(PORT_OLED_RESET, PIN_OLED_RESET, GPIO_PIN_SET);
  HAL_GPIO_WritePin(PORT_OLED_CS, PIN_OLED_CS, GPIO_PIN_SET);
  HAL_GPIO_WritePin(PORT_OLED_DC, PIN_OLED_DC, GPIO_PIN_SET);
}

static inline void setpin_reset(GDisplay *g, bool_t state) {
  (void) g;
  if (state)
    HAL_GPIO_WritePin(PORT_OLED_RESET, PIN_OLED_RESET, GPIO_PIN_RESET);
  else
    HAL_GPIO_WritePin(PORT_OLED_RESET, PIN_OLED_RESET, GPIO_PIN_SET);
}

static inline void acquire_bus(GDisplay *g) {
  HAL_GPIO_WritePin(PORT_OLED_CS, PIN_OLED_CS, GPIO_PIN_RESET);
}

static inline void release_bus(GDisplay *g) {
  HAL_GPIO_WritePin(PORT_OLED_CS, PIN_OLED_CS, GPIO_PIN_SET);
}

static inline void write_cmd(GDisplay *g, uint8_t index) {
  (void) g;
  HAL_GPIO_WritePin(PORT_OLED_DC, PIN_OLED_DC, GPIO_PIN_RESET);
  HAL_SPI_Transmit(&hspi1, &index, 1, HAL_MAX_DELAY);
  HAL_GPIO_WritePin(PORT_OLED_DC, PIN_OLED_DC, GPIO_PIN_SET);
}

static inline void write_data(GDisplay *g, uint8_t data) {
  (void) g;
  HAL_SPI_Transmit(&hspi1, &data, 1, HAL_MAX_DELAY);
}
There are some other empty functions in there, which are not needed and omitted in the above snippet. As you can see it's just a matter of setting the display's control pins and sending single bytes via SPI, which is easily done with ST's HAL. GPIO and SPI initialization code was generated by CubeMX and is called by main(), but it could also be added to the init_board() function.

And it actually works:

uGFX without widgets (and everything that would come with them) takes about 6kB flash and a few hundred bytes (something between 300 and 400) of RAM. That includes one of uGFX's fonts stored in flash.

Discussions