Skip to content

Commit

Permalink
Add API for OLED
Browse files Browse the repository at this point in the history
  • Loading branch information
gautam-dev-maker authored and VedantParanjape committed Feb 23, 2022
1 parent dabdd8c commit 786a6c2
Show file tree
Hide file tree
Showing 7 changed files with 583 additions and 3 deletions.
98 changes: 96 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,100 @@
set(srcs "src/i2cdev.c" "src/adc.c" "src/bar_graph.c" "src/switches.c" "src/lsa.c" "src/motor_driver.c" "src/mpu6050.c" "src/servo.c" "src/utils.c")
set(include_dirs include)

if(CONFIG_ENABLE_OLED)
list(APPEND include_dirs u8g2/csrc)
list(APPEND srcs "src/oled.c" "src/u8g2_esp32_hal.c")
list(APPEND srcs "u8g2/csrc/u8x8_setup.c"
"u8g2/csrc/u8x8_u8toa.c"
"u8g2/csrc/u8x8_d_ssd1306_96x16.c"
"u8g2/csrc/u8g2_d_memory.c"
"u8g2/csrc/u8g2_selection_list.c"
"u8g2/csrc/u8g2_hvline.c"
"u8g2/csrc/u8x8_d_ssd1306_128x64_noname.c"
"u8g2/csrc/u8x8_message.c"
"u8g2/csrc/u8x8_d_ssd1306_48x64.c"
"u8g2/csrc/u8x8_d_ssd1305.c"
"u8g2/csrc/u8g2_kerning.c"
"u8g2/csrc/u8x8_input_value.c"
"u8g2/csrc/u8x8_d_st7586s_s028hn118a.c"
"u8g2/csrc/u8g2_polygon.c"
"u8g2/csrc/u8x8_d_uc1604.c"
"u8g2/csrc/u8x8_d_ssd1306_128x32.c"
"u8g2/csrc/u8x8_d_ssd1322.c"
"u8g2/csrc/u8x8_d_sbn1661.c"
"u8g2/csrc/u8g2_input_value.c"
"u8g2/csrc/u8x8_8x8.c"
"u8g2/csrc/u8x8_debounce.c"
"u8g2/csrc/u8x8_d_uc1638.c"
"u8g2/csrc/u8g2_setup.c"
"u8g2/csrc/u8x8_d_ist3020.c"
"u8g2/csrc/u8x8_display.c"
"u8g2/csrc/u8x8_d_ssd1317.c"
"u8g2/csrc/u8x8_d_ks0108.c"
"u8g2/csrc/u8g2_box.c"
"u8g2/csrc/u8x8_selection_list.c"
"u8g2/csrc/u8x8_d_ssd1326.c"
"u8g2/csrc/u8x8_d_st75256.c"
"u8g2/csrc/u8x8_d_ssd1309.c"
"u8g2/csrc/u8x8_byte.c"
"u8g2/csrc/u8x8_d_ssd1607_200x200.c"
"u8g2/csrc/u8x8_d_pcd8544_84x48.c"
"u8g2/csrc/u8log.c"
"u8g2/csrc/u8x8_d_sh1107.c"
"u8g2/csrc/u8log_u8x8.c"
"u8g2/csrc/u8g2_message.c"
"u8g2/csrc/u8x8_d_uc1610.c"
"u8g2/csrc/u8x8_d_sh1106_72x40.c"
"u8g2/csrc/u8g2_line.c"
"u8g2/csrc/u8g2_intersection.c"
"u8g2/csrc/u8g2_fonts.c"
"u8g2/csrc/u8x8_d_sh1106_64x32.c"
"u8g2/csrc/u8x8_d_sed1330.c"
"u8g2/csrc/u8x8_d_pcf8814_hx1230.c"
"u8g2/csrc/u8x8_d_il3820_296x128.c"
"u8g2/csrc/u8x8_d_uc1701_dogs102.c"
"u8g2/csrc/u8g2_cleardisplay.c"
"u8g2/csrc/u8x8_d_ssd1325.c"
"u8g2/csrc/u8g2_font.c"
"u8g2/csrc/u8x8_d_uc1601.c"
"u8g2/csrc/u8x8_d_pcf8812.c"
"u8g2/csrc/u8x8_cad.c"
"u8g2/csrc/u8x8_d_uc1611.c"
"u8g2/csrc/u8x8_string.c"
"u8g2/csrc/u8g2_ll_hvline.c"
"u8g2/csrc/u8x8_fonts.c"
"u8g2/csrc/u8x8_d_ld7032_60x32.c"
"u8g2/csrc/u8x8_d_max7219.c"
"u8g2/csrc/u8x8_d_st7588.c"
"u8g2/csrc/u8x8_d_ssd1606_172x72.c"
"u8g2/csrc/u8x8_d_st7586s_erc240160.c"
"u8g2/csrc/u8x8_d_stdio.c"
"u8g2/csrc/u8x8_d_sh1122.c"
"u8g2/csrc/u8log_u8g2.c"
"u8g2/csrc/u8g2_circle.c"
"u8g2/csrc/u8x8_d_ssd1306_64x48.c"
"u8g2/csrc/u8g2_buffer.c"
"u8g2/csrc/u8g2_bitmap.c"
"u8g2/csrc/u8x8_d_lc7981.c"
"u8g2/csrc/u8x8_d_st7920.c"
"u8g2/csrc/u8x8_d_t6963.c"
"u8g2/csrc/u8x8_d_st7567.c"
"u8g2/csrc/u8x8_d_ls013b7dh03.c"
"u8g2/csrc/u8x8_d_ssd1327.c"
"u8g2/csrc/u8x8_d_sh1108.c"
"u8g2/csrc/u8x8_gpio.c"
"u8g2/csrc/u8x8_d_uc1608.c"
"u8g2/csrc/u8x8_d_uc1617.c"
"u8g2/csrc/u8x8_d_ssd1329.c"
"u8g2/csrc/u8x8_d_ssd1306_64x32.c"
"u8g2/csrc/u8g2_d_setup.c"
"u8g2/csrc/u8x8_d_uc1701_mini12864.c"
"u8g2/csrc/u8x8_u16toa.c"
"u8g2/csrc/u8x8_d_a2printer.c"
"u8g2/csrc/u8x8_d_st7565.c")
endif()

idf_component_register(SRCS "${srcs}"
INCLUDE_DIRS "include"
INCLUDE_DIRS "${include_dirs}"
REQUIRES driver efuse esp32 esp_adc_cal esp_common esp_event
esp_rom freertos heap log soc spiffs)
esp_rom freertos heap log soc spiffs)
60 changes: 60 additions & 0 deletions include/oled.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* MIT License
*
* Copyright (c) 2021 Society of Robotics and Automation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#ifndef OLED_H
#define OLED_H

#include <stdio.h>
#include <string.h>

#include <driver/gpio.h>
#include <esp_log.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include "pin_defs.h"

#ifdef CONFIG_ENABLE_OLED
#include "u8g2.h"
#include "u8g2_esp32_hal.h"
#endif

/**
* @brief enables and configures OLED display
* @param pointer to empty u8g2_t struct
* @return esp_err_t i.e it shows if OLED is initialised successfully or not
**/
esp_err_t init_oled(u8g2_t* u8g2);

/**
* @brief displays SRA logo on OLED screen
* @param pointer to u8g2_t struct
* @return esp_err_t i.e it shows if SRA logo is displayed successfully or not
**/
esp_err_t display_logo(u8g2_t* u8g2);

#endif
8 changes: 7 additions & 1 deletion include/pin_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@

/////////////////////////////

#ifdef CONFIG_ENABLE_OLED
//////// oled ////////
#define OLED_SDA 22
#define OLED_SCL 21
#endif

//////// bar graph //////////
#define BG_LED_1 32
#define BG_LED_2 33
Expand Down Expand Up @@ -98,4 +104,4 @@
#define SERVO_C 19
/////////////////////////////

#endif
#endif
4 changes: 4 additions & 0 deletions include/sra_board.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@
#include "pin_defs.h"
#include "utils.h"

#ifdef CONFIG_ENABLE_OLED
#include "oled.h"
#endif

#endif
44 changes: 44 additions & 0 deletions include/u8g2_esp32_hal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* u8g2_esp32_hal.h
*
* Created on: Feb 12, 2017
* Author: kolban
*/

#ifndef U8G2_ESP32_HAL_H_
#define U8G2_ESP32_HAL_H_
#include "u8g2.h"
#include "driver/gpio.h"
#include "driver/spi_master.h"
#include "driver/i2c.h"

#define U8G2_ESP32_HAL_UNDEFINED (-1)

#define I2C_MASTER_OLED_NUM I2C_NUM_0 // I2C port number for master dev
#define I2C_MASTER_TX_BUF_DISABLE 0 // I2C master do not need buffer
#define I2C_MASTER_RX_BUF_DISABLE 0 // I2C master do not need buffer
#define I2C_MASTER_OLED_FREQ_HZ 50000 // I2C master clock frequency
#define ACK_CHECK_EN 0x1 // I2C master will check ack from slave
#define ACK_CHECK_DIS 0x0 // I2C master will not check ack from slave

typedef struct
{
gpio_num_t clk;
gpio_num_t mosi;
gpio_num_t sda; // data for I²C
gpio_num_t scl; // clock for I²C
gpio_num_t cs;
gpio_num_t reset;
gpio_num_t dc;
} u8g2_esp32_hal_t;

#define U8G2_ESP32_HAL_DEFAULT \
{ \
U8G2_ESP32_HAL_UNDEFINED, U8G2_ESP32_HAL_UNDEFINED, U8G2_ESP32_HAL_UNDEFINED, U8G2_ESP32_HAL_UNDEFINED, U8G2_ESP32_HAL_UNDEFINED, U8G2_ESP32_HAL_UNDEFINED, U8G2_ESP32_HAL_UNDEFINED \
}

void u8g2_esp32_hal_init(u8g2_esp32_hal_t u8g2_esp32_hal_param);
uint8_t u8g2_esp32_spi_byte_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
uint8_t u8g2_esp32_i2c_byte_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
uint8_t u8g2_esp32_gpio_and_delay_cb(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
#endif /* U8G2_ESP32_HAL_H_ */
100 changes: 100 additions & 0 deletions src/oled.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* MIT License
*
* Copyright (c) 2021 Society of Robotics and Automation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#include "oled.h"

static const char *TAG_OLED = "oled";

const unsigned char sra_logo[] = {
0b11111111,0b11111111,0b11111111,0b11111111,0b11111111,0b11111111,0b11111111,0b11111111,0b11111111,
0b11111111,0b10000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00111111,0b11111111,
0b11111110,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00001111,0b11111111,
0b11111110,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00001111,0b11111111,
0b11111100,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000111,0b11111111,
0b11111100,0b00000000,0b00000000,0b00000001,0b00000000,0b00000000,0b00000000,0b00000111,0b11111111,
0b11111100,0b00000000,0b00000000,0b00000000,0b10000000,0b00000000,0b00000000,0b00000111,0b11111111,
0b11111100,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000000,0b00000111,0b11111111,
0b11111100,0b00000000,0b00000000,0b00000000,0b01000000,0b00000000,0b00000000,0b00000111,0b11111111,
0b11111100,0b01111100,0b11111000,0b00111111,0b11111110,0b00000000,0b00111100,0b00000111,0b11111111,
0b11111100,0b11111100,0b11111100,0b00111111,0b11111111,0b00000000,0b01111100,0b00000111,0b11111111,
0b11111101,0b11111100,0b11111110,0b00111111,0b11111111,0b00000000,0b01111110,0b00000111,0b11111111,
0b11111101,0b11100000,0b00011100,0b00000000,0b00110111,0b00000000,0b11111110,0b00000111,0b11111111,
0b11111101,0b11100000,0b00000000,0b00000000,0b00110111,0b00000001,0b11111111,0b00000111,0b11111111,
0b11111101,0b11111100,0b11111000,0b00000000,0b00111111,0b00000001,0b11100111,0b10000111,0b11111111,
0b11111100,0b11111100,0b11111100,0b00111111,0b11111111,0b00000011,0b11000111,0b10000111,0b11111111,
0b11111100,0b01111000,0b11111110,0b00111111,0b11111111,0b00000011,0b11000011,0b11000111,0b11111111,
0b11111100,0b00000000,0b00011110,0b00111111,0b01111111,0b00000111,0b10000011,0b11000111,0b11111111,
0b11111101,0b11100000,0b00011110,0b00111000,0b00110111,0b00000111,0b00000001,0b11100111,0b11111111,
0b11111111,0b11111100,0b11111100,0b00111000,0b00110111,0b00001111,0b00000001,0b11100111,0b11111111,
0b11111110,0b11111100,0b11111100,0b00111000,0b01100111,0b00011110,0b00000000,0b11110111,0b11111111,
0b11111111,0b00111000,0b01110000,0b00110000,0b01100111,0b00000000,0b00000000,0b00000111,0b11111111,
0b11111111,0b00000000,0b00000000,0b00000000,0b11100000,0b00000000,0b00000000,0b00000111,0b11111111,
0b11111111,0b10000000,0b00000000,0b00000001,0b11000000,0b00000000,0b00000000,0b00000111,0b11111111,
0b11111111,0b11000000,0b00000000,0b00000011,0b10000000,0b00000000,0b00000000,0b00000111,0b11111111,
0b11111111,0b11100000,0b00000000,0b00000111,0b10000000,0b00000000,0b00000000,0b00000111,0b11111111,
0b11111111,0b11111000,0b00000000,0b00011111,0b00000000,0b00000000,0b00000000,0b00000111,0b11111111,
0b11111111,0b11111110,0b00000000,0b01111110,0b00000000,0b00000000,0b00000000,0b00000111,0b11111111,
0b11111111,0b11111111,0b11111111,0b11111000,0b00000000,0b00000000,0b00000000,0b00000111,0b11111111,
0b11111111,0b11111111,0b11111111,0b11110000,0b00000000,0b00000000,0b00000000,0b00001111,0b11111111,
0b11111111,0b11111111,0b11111111,0b11000000,0b00000000,0b00000000,0b00000000,0b00111111,0b11111111,
0b11111111,0b11111111,0b11111111,0b11111111,0b11111111,0b11111111,0b11111111,0b11111111,0b11111111,
};

esp_err_t init_oled(u8g2_t* u8g2)
{

u8g2_esp32_hal_t u8g2_esp32_hal = U8G2_ESP32_HAL_DEFAULT;
u8g2_esp32_hal.sda = OLED_SDA;
u8g2_esp32_hal.scl = OLED_SCL;
u8g2_esp32_hal_init(u8g2_esp32_hal);

u8g2_Setup_ssd1306_i2c_128x32_univision_f(
u8g2,
U8G2_R0,
u8g2_esp32_i2c_byte_cb,
u8g2_esp32_gpio_and_delay_cb);

u8x8_SetI2CAddress(&u8g2->u8x8,0x78);

u8g2_InitDisplay(u8g2);

u8g2_SetPowerSave(u8g2, 0);
u8g2_ClearBuffer(u8g2);
display_logo(u8g2);
u8g2_SendBuffer(u8g2);

ESP_LOGI(TAG_OLED, "Configured OLED Display");

return ESP_OK;
}

esp_err_t display_logo(u8g2_t* u8g2)
{
u8g2_DrawBox(u8g2, 0, 0, 128, 64);
u8g2_DrawBitmap(u8g2,27,0,9,36,sra_logo);

ESP_LOGI(TAG_OLED, "Displayed SRA logo on OLED Screen");

return ESP_OK;
}
Loading

0 comments on commit 786a6c2

Please sign in to comment.