Trouble adding functions to Daisy Oled

I am trying to add some new functions to the Daisy OLED Driver/Library.

Right now there is no support for Bitmaps and I would like to add that.

I am pulling my hair out trying to figure out where to add it.

I tried adding it after the DrawPixel function in dev/oled_ssd130x.h but i just get errors in my main program saying it can not find the function.

i wonder if instead I should be adding it to
display.h or oled_display.h??
I keep wondering if Part of the issue is that oled_ssd130x.h uses a template class and I would need to add another header file for my function but I am not even sure if dev/oled_ssd130x.h is the right place to add the additional function.

here is the function

/* Draw a bitmap */
void DrawBitmap(uint8_t x, uint8_t y, const unsigned char* bitmap, uint8_t w, uint8_t  h, bool on) {
    int16_t byteWidth = (w + 7) / 8; // Bitmap scanline pad = whole byte
    uint8_t byte = 0;

    if (x >= SSD1306_WIDTH || y >= SSD1306_HEIGHT) {
        return;
    }

    for (uint8_t j = 0; j < h; j++, y++) {
        for (uint8_t i = 0; i < w; i++) {
            if (i & 7) {
                byte <<= 1;
            } else {
                byte = (*(const unsigned char *)(&bitmap[j * byteWidth + i / 8]));
            }

            if (byte & 0x80) {
               DrawPixel(x + i, y, on); 
            }
        }
    }
    return;
}

thanks for any help

here is some additional info on how CUBEMX drivers do it

for reference here are two other stm32 Oled Libraries I am trying to grab functions from or use to enhance/replace the daisy oled_ssd130x.h template class

UG82 stm32

[https://github.com/afiskon/stm32-ssd1306/blob/7e0c25d90250630b51202f5079f75e7b59d732f8/ssd1306/ssd1306.h#L61](https://stm32 Oled Library )

my issue here is a conceptual one. I do not understand how to apply the cubeIDE style drivers which call HAL libraries to the Daisy Framework. If this was a Cube Project I would just add the headers and the files etc but as Daisy uses Intermediate Template classes etc I am getting stuck — even if I was to ditch the Daisy display drivers I am still confused as to whether or not I could use the HAL commands.

  1. in the u8g2 library all the calls are HAL GPIO pins and the SPI TYPEDEF HSPI

I CAN FIND HSPI in the daisy folder CUBE/DAISY_SEED_REV4/INC
But I cant find any other references to it being used. This is the problem I always end up having. Coming from a CUBEMX background, I do not understand how to make STM32 drivers work with the DaisyLib when most of the systems do not use the same names as the Cube Names.

void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
{

  GPIO_InitTypeDef GPIO_InitStruct;
  if(hspi->Instance==SPI2)
  {
  /* USER CODE BEGIN SPI2_MspInit 0 */

  /* USER CODE END SPI2_MspInit 0 */
    /* Peripheral clock enable */
    __HAL_RCC_SPI2_CLK_ENABLE();
  
    /**SPI2 GPIO Configuration    
    PB13     ------> SPI2_SCK
    PB15     ------> SPI2_MOSI 
    */
    GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_15;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  /* USER CODE BEGIN SPI2_MspInit 1 */

  /* USER CODE END SPI2_MspInit 1 */
  }

}

In the other STM32 driver there are DEFINES for the ports and addresses. but I am not sure If i need to use the TRANSPORT CONFIG?

// I2C Configuration
#define SSD1306_I2C_PORT        hi2c1
#define SSD1306_I2C_ADDR        (0x3C << 1)

// SPI Configuration
//#define SSD1306_SPI_PORT        hspi1
//#define SSD1306_CS_Port         OLED_CS_GPIO_Port
//#define SSD1306_CS_Pin          OLED_CS_Pin
//#define SSD1306_DC_Port         OLED_DC_GPIO_Port
//#define SSD1306_DC_Pin          OLED_DC_Pin
//#define SSD1306_Reset_Port      OLED_Res_GPIO_Port
//#define SSD1306_Reset_Pin       OLED_Res_Pin

AND it also calls the I2C typedef

void HAL_I2C_MspInit(I2C_HandleTypeDef* hi2c)
{

  GPIO_InitTypeDef GPIO_InitStruct;
  if(hi2c->Instance==I2C1)
  {
  /* USER CODE BEGIN I2C1_MspInit 0 */

  /* USER CODE END I2C1_MspInit 0 */
  
    /**I2C1 GPIO Configuration    
    PB8     ------> I2C1_SCL
    PB9     ------> I2C1_SDA 
    */
    GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
    GPIO_InitStruct.Pull = GPIO_PULLUP;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

    /* Peripheral clock enable */
    __HAL_RCC_I2C1_CLK_ENABLE();
  /* USER CODE BEGIN I2C1_MspInit 1 */

  /* USER CODE END I2C1_MspInit 1 */
  }

}

void HAL_I2C_MspDeInit(I2C_HandleTypeDef* hi2c)
{

  if(hi2c->Instance==I2C1)
  {
  /* USER CODE BEGIN I2C1_MspDeInit 0 */

  /* USER CODE END I2C1_MspDeInit 0 */
    /* Peripheral clock disable */
    __HAL_RCC_I2C1_CLK_DISABLE();
  
    /**I2C1 GPIO Configuration    
    PB8     ------> I2C1_SCL
    PB9     ------> I2C1_SDA 
    */
    HAL_GPIO_DeInit(GPIOB, GPIO_PIN_8|GPIO_PIN_9);

  /* USER CODE BEGIN I2C1_MspDeInit 1 */

  /* USER CODE END I2C1_MspDeInit 1 */
  }

}

Good News

I figured it out!

Adding this function toward the BOTTOM of Display.H (in daisy SRC)

  void DrawMyBitmap(uint_fast8_t x,uint_fast8_t y,const uint8_t* bitmap,uint_fast8_t w,uint_fast8_t h, bool on)
    {
    uint_fast8_t byteWidth = (w + 7) / 8; // Bitmap scanline pad = whole byte
    uint8_t byte = 0;
    for (uint_fast8_t j = 0; j < h; j++, y++) {
        for (uint_fast8_t i = 0; i < w; i++) {
            if (i & 7)
                byte <<= 1;
            else
                byte = bitmap[j * byteWidth + i / 8];
            if (byte & 0x80)
                ((ChildType*)(this))->ChildType::DrawPixel(x + i,  y, on);
        }
    }
}

allows for calling a bitmap from your main file


 patch.display.DrawMyBitmap(0, 0, github_logo_64x64, 64, 64, true);


1 Like