Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
/*******************************************************************************
* File Name: user_oled.c
*
* Description: This file contains driver code for oled display.
*
* Related Document: See README.md
*
*
********************************************************************************
* Copyright 2021-2024, Cypress Semiconductor Corporation (an Infineon company) or
* an affiliate of Cypress Semiconductor Corporation. All rights reserved.
*
* This software, including source code, documentation and related
* materials ("Software") is owned by Cypress Semiconductor Corporation
* or one of its affiliates ("Cypress") and is protected by and subject to
* worldwide patent protection (United States and foreign),
* United States copyright laws and international treaty provisions.
* Therefore, you may use this Software only as provided in the license
* agreement accompanying the software package from which you
* obtained this Software ("EULA").
* If no EULA applies, Cypress hereby grants you a personal, non-exclusive,
* non-transferable license to copy, modify, and compile the Software
* source code solely for use in connection with Cypress's
* integrated circuit products. Any reproduction, modification, translation,
* compilation, or representation of this Software except as specified
* above is prohibited without the express written permission of Cypress.
*
* Disclaimer: THIS SOFTWARE IS PROVIDED AS-IS, WITH NO WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT, IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress
* reserves the right to make changes to the Software without notice. Cypress
* does not assume any liability arising out of the application or use of the
* Software or any product or circuit described in the Software. Cypress does
* not authorize its products for use in any products where a malfunction or
* failure of the Cypress product may reasonably be expected to result in
* significant property damage, injury or death ("High Risk Product"). By
* including Cypress's product in a High Risk Product, the manufacturer
* of such system or application assumes all risk of such use and in doing
* so agrees to indemnify Cypress against all liability.
*******************************************************************************/
/*******************************************************************************
* Header file includes
******************************************************************************/
#include "cyhal.h"
#include "cybsp.h"
#include "cy_retarget_io.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "mtb_ssd1306.h"
#include "mtb_ssd1306_i2c.h"
#include "user_oled.h"
/*******************************************************************************
* Macros
******************************************************************************/
/* I2C slave address to communicate with */
#define I2C_SLAVE_ADDR (SSD1309_I2C_ADDRESS)
/* I2C bus frequency */
#define I2C_FREQ (400000u)
/* Packet size */
#define PACKET_SIZE (SSD1309_LCDWIDTH + 1u)
/* Display lines */
#define DISP_MAX_LINE (SSD1309_LCDHEIGHT / 8u)
#define FONT5x8_CHAR_WIDTH (6u)
#define FONT12x16_CHAR_WIDTH (13u)
/*******************************************************************************
* Global Variables
******************************************************************************/
cyhal_i2c_t i2c_obj;
/* I2C transmit buffer array*/
uint8_t txBuff[PACKET_SIZE + 1u];
/* Default font array */
static const uint8_t font5x8[][5] = {
{0x00, 0x00, 0x00, 0x00, 0x00}, // SPACE
{0x00, 0x00, 0x5F, 0x00, 0x00}, // !
{0x00, 0x03, 0x00, 0x03, 0x00}, // "
{0x14, 0x3E, 0x14, 0x3E, 0x14}, // #
{0x24, 0x2A, 0x7F, 0x2A, 0x12}, // $
{0x43, 0x33, 0x08, 0x66, 0x61}, // %
{0x36, 0x49, 0x55, 0x22, 0x50}, // &
{0x00, 0x05, 0x03, 0x00, 0x00}, // '
{0x00, 0x1C, 0x22, 0x41, 0x00}, // (
{0x00, 0x41, 0x22, 0x1C, 0x00}, // )
{0x14, 0x08, 0x3E, 0x08, 0x14}, // *
{0x08, 0x08, 0x3E, 0x08, 0x08}, // +
{0x00, 0x50, 0x30, 0x00, 0x00}, // ,
{0x08, 0x08, 0x08, 0x08, 0x08}, // -
{0x00, 0x60, 0x60, 0x00, 0x00}, // .
{0x20, 0x10, 0x08, 0x04, 0x02}, // /
{0x3E, 0x51, 0x49, 0x45, 0x3E}, // 0
{0x04, 0x02, 0x7F, 0x00, 0x00}, // 1
{0x42, 0x61, 0x51, 0x49, 0x46}, // 2
{0x22, 0x41, 0x49, 0x49, 0x36}, // 3
{0x18, 0x14, 0x12, 0x7F, 0x10}, // 4
{0x27, 0x45, 0x45, 0x45, 0x39}, // 5
{0x3E, 0x49, 0x49, 0x49, 0x32}, // 6
{0x01, 0x01, 0x71, 0x09, 0x07}, // 7
{0x36, 0x49, 0x49, 0x49, 0x36}, // 8
{0x26, 0x49, 0x49, 0x49, 0x3E}, // 9
{0x00, 0x36, 0x36, 0x00, 0x00}, // :
{0x00, 0x56, 0x36, 0x00, 0x00}, // ;
{0x08, 0x14, 0x22, 0x41, 0x00}, // <
{0x14, 0x14, 0x14, 0x14, 0x14}, // =
{0x00, 0x41, 0x22, 0x14, 0x08}, // >
{0x02, 0x01, 0x51, 0x09, 0x06}, // ?
{0x3E, 0x41, 0x59, 0x55, 0x5E}, // @
{0x7E, 0x09, 0x09, 0x09, 0x7E}, // A
{0x7F, 0x49, 0x49, 0x49, 0x36}, // B
{0x3E, 0x41, 0x41, 0x41, 0x22}, // C
{0x7F, 0x41, 0x41, 0x41, 0x3E}, // D
{0x7F, 0x49, 0x49, 0x49, 0x41}, // E
{0x7F, 0x09, 0x09, 0x09, 0x01}, // F
{0x3E, 0x41, 0x41, 0x49, 0x3A}, // G
{0x7F, 0x08, 0x08, 0x08, 0x7F}, // H
{0x00, 0x41, 0x7F, 0x41, 0x00}, // I
{0x30, 0x40, 0x40, 0x40, 0x3F}, // J
{0x7F, 0x08, 0x14, 0x22, 0x41}, // K
{0x7F, 0x40, 0x40, 0x40, 0x40}, // L
{0x7F, 0x02, 0x0C, 0x02, 0x7F}, // M
{0x7F, 0x02, 0x04, 0x08, 0x7F}, // N
{0x3E, 0x41, 0x41, 0x41, 0x3E}, // O
{0x7F, 0x09, 0x09, 0x09, 0x06}, // P
{0x1E, 0x21, 0x21, 0x21, 0x5E}, // Q
{0x7F, 0x09, 0x09, 0x09, 0x76}, // R
{0x26, 0x49, 0x49, 0x49, 0x32}, // S
{0x01, 0x01, 0x7F, 0x01, 0x01}, // T
{0x3F, 0x40, 0x40, 0x40, 0x3F}, // U
{0x1F, 0x20, 0x40, 0x20, 0x1F}, // V
{0x7F, 0x20, 0x10, 0x20, 0x7F}, // W
{0x41, 0x22, 0x1C, 0x22, 0x41}, // X
{0x07, 0x08, 0x70, 0x08, 0x07}, // Y
{0x61, 0x51, 0x49, 0x45, 0x43}, // Z
{0x00, 0x7F, 0x41, 0x00, 0x00}, // [
{0x02, 0x04, 0x08, 0x10, 0x20}, // '\'
{0x00, 0x00, 0x41, 0x7F, 0x00}, // ]
{0x04, 0x02, 0x01, 0x02, 0x04}, // ^
{0x40, 0x40, 0x40, 0x40, 0x40}, // _
{0x00, 0x01, 0x02, 0x04, 0x00}, // `
{0x20, 0x54, 0x54, 0x54, 0x78}, // a
{0x7F, 0x44, 0x44, 0x44, 0x38}, // b
{0x38, 0x44, 0x44, 0x44, 0x44}, // c
{0x38, 0x44, 0x44, 0x44, 0x7F}, // d
{0x38, 0x54, 0x54, 0x54, 0x18}, // e
{0x04, 0x04, 0x7E, 0x05, 0x05}, // f
{0x08, 0x54, 0x54, 0x54, 0x3C}, // g
{0x7F, 0x08, 0x04, 0x04, 0x78}, // h
{0x00, 0x44, 0x7D, 0x40, 0x00}, // i
{0x20, 0x40, 0x44, 0x3D, 0x00}, // j
{0x7F, 0x10, 0x28, 0x44, 0x00}, // k
{0x00, 0x41, 0x7F, 0x40, 0x00}, // l
{0x7C, 0x04, 0x78, 0x04, 0x78}, // m
{0x7C, 0x08, 0x04, 0x04, 0x78}, // n
{0x38, 0x44, 0x44, 0x44, 0x38}, // o
{0x7C, 0x14, 0x14, 0x14, 0x08}, // p
{0x08, 0x14, 0x14, 0x14, 0x7C}, // q
{0x00, 0x7C, 0x08, 0x04, 0x04}, // r
{0x48, 0x54, 0x54, 0x54, 0x20}, // s
{0x04, 0x04, 0x3F, 0x44, 0x44}, // t
{0x3C, 0x40, 0x40, 0x20, 0x7C}, // u
{0x1C, 0x20, 0x40, 0x20, 0x1C}, // v
{0x3C, 0x40, 0x30, 0x40, 0x3C}, // w
{0x44, 0x28, 0x10, 0x28, 0x44}, // x
{0x0C, 0x50, 0x50, 0x50, 0x3C}, // y
{0x44, 0x64, 0x54, 0x4C, 0x44}, // z
{0x00, 0x08, 0x36, 0x41, 0x41}, // {
{0x00, 0x00, 0x7F, 0x00, 0x00}, // |
{0x41, 0x41, 0x36, 0x08, 0x00}, // }
{0x02, 0x01, 0x02, 0x04, 0x02} // ~
};
/* Font array for large text*/
const uint8_t font12x16[][26]={
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // Code for char
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C, 0x00, 0xFF, 0x33, 0xFF, 0x33, 0xFF, 0x33, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // Code for char !
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x3C, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x3C, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // Code for char "
{0x00, 0x00, 0x00, 0x02, 0x10, 0x1E, 0x90, 0x1F, 0xF0, 0x1F, 0xFE, 0x03, 0x7E, 0x1E, 0x9E, 0x1F, 0xF0, 0x1F, 0xFE, 0x03, 0x7E, 0x02, 0x1E, 0x00, 0x10, 0x00}, // Code for char #
{0x00, 0x00, 0x00, 0x00, 0x78, 0x04, 0xFC, 0x0C, 0xFC, 0x0C, 0xFF, 0x3F, 0xFF, 0x3F, 0xFF, 0x3F, 0xCC, 0x0F, 0xCC, 0x0F, 0x88, 0x07, 0x00, 0x00, 0x00, 0x00}, // Code for char $
{0x00, 0x00, 0x00, 0x30, 0x38, 0x38, 0x38, 0x3C, 0x38, 0x1E, 0x38, 0x0F, 0x80, 0x07, 0xC0, 0x03, 0xE0, 0x39, 0xF0, 0x38, 0x78, 0x38, 0x3C, 0x38, 0x1C, 0x00}, // Code for char %
{0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0xB8, 0x3F, 0xFC, 0x3F, 0xFE, 0x31, 0xE6, 0x37, 0xFE, 0x3F, 0x3E, 0x1E, 0x1C, 0x3E, 0x00, 0x36, 0x00, 0x22, 0x00, 0x00}, // Code for char &
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x27, 0x00, 0x3F, 0x00, 0x3F, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // Code for char '
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x03, 0xFC, 0x0F, 0xFE, 0x1F, 0xFF, 0x3F, 0x07, 0x38, 0x01, 0x20, 0x01, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // Code for char (
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x20, 0x01, 0x20, 0x07, 0x38, 0xFF, 0x3F, 0xFE, 0x1F, 0xFC, 0x0F, 0xF0, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // Code for char )
{0x00, 0x00, 0x00, 0x00, 0x98, 0x0C, 0xB8, 0x0E, 0xF8, 0x0F, 0xF8, 0x0F, 0xF8, 0x0F, 0xF8, 0x0F, 0xF8, 0x0F, 0xB8, 0x0E, 0x98, 0x0C, 0x00, 0x00, 0x00, 0x00}, // Code for char *
{0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0xF0, 0x0F, 0xF0, 0x0F, 0xF0, 0x0F, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00}, // Code for char +
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB8, 0x00, 0xF8, 0x00, 0xF8, 0x00, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // Code for char ,
{0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00}, // Code for char -
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // Code for char .
{0x00, 0x00, 0x00, 0x18, 0x00, 0x1C, 0x00, 0x1E, 0x00, 0x0F, 0x80, 0x07, 0xC0, 0x03, 0xE0, 0x01, 0xF0, 0x00, 0x78, 0x00, 0x3C, 0x00, 0x1E, 0x00, 0x0E, 0x00}, // Code for char /
{0x00, 0x00, 0xF8, 0x07, 0xFE, 0x1F, 0xFE, 0x1F, 0x07, 0x3F, 0x83, 0x33, 0xC3, 0x31, 0xE3, 0x30, 0x73, 0x30, 0x3F, 0x38, 0xFE, 0x1F, 0xFE, 0x1F, 0xF8, 0x07}, // Code for char 0
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x30, 0x0C, 0x30, 0x0E, 0x30, 0xFF, 0x3F, 0xFF, 0x3F, 0xFF, 0x3F, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x00}, // Code for char 1
{0x00, 0x00, 0x1C, 0x30, 0x1E, 0x38, 0x1F, 0x3C, 0x07, 0x3E, 0x03, 0x3F, 0x83, 0x37, 0xC3, 0x33, 0xE3, 0x31, 0xF7, 0x30, 0x7F, 0x30, 0x3E, 0x30, 0x1C, 0x30}, // Code for char 2
{0x00, 0x00, 0x0C, 0x0C, 0x0E, 0x1C, 0x0F, 0x3C, 0xC7, 0x38, 0xC3, 0x30, 0xC3, 0x30, 0xC3, 0x30, 0xC3, 0x30, 0xE7, 0x39, 0xFF, 0x3F, 0x7E, 0x1F, 0x3C, 0x0E}, // Code for char 3
{0x00, 0x00, 0xC0, 0x03, 0xE0, 0x03, 0xF0, 0x03, 0x78, 0x03, 0x3C, 0x03, 0x1E, 0x03, 0x0F, 0x03, 0xFF, 0x3F, 0xFF, 0x3F, 0xFF, 0x3F, 0x00, 0x03, 0x00, 0x03}, // Code for char 4
{0x00, 0x00, 0x3F, 0x0C, 0x7F, 0x1C, 0x7F, 0x3C, 0x63, 0x38, 0x63, 0x30, 0x63, 0x30, 0x63, 0x30, 0x63, 0x30, 0xE3, 0x38, 0xE3, 0x3F, 0xC3, 0x1F, 0x83, 0x0F}, // Code for char 5
{0x00, 0x00, 0xC0, 0x0F, 0xF0, 0x1F, 0xF8, 0x3F, 0xFC, 0x39, 0xDE, 0x30, 0xCF, 0x30, 0xC7, 0x30, 0xC3, 0x30, 0xC3, 0x39, 0xC3, 0x3F, 0x80, 0x1F, 0x00, 0x0F}, // Code for char 6
{0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x30, 0x03, 0x3C, 0x03, 0x3F, 0xC3, 0x0F, 0xF3, 0x03, 0xFF, 0x00, 0x3F, 0x00, 0x0F, 0x00, 0x03, 0x00}, // Code for char 7
{0x00, 0x00, 0x00, 0x0F, 0xBC, 0x1F, 0xFE, 0x3F, 0xFF, 0x39, 0xE7, 0x30, 0xC3, 0x30, 0xC3, 0x30, 0xE7, 0x30, 0xFF, 0x39, 0xFE, 0x3F, 0xBC, 0x1F, 0x00, 0x0F}, // Code for char 8
{0x00, 0x00, 0x3C, 0x00, 0x7E, 0x00, 0xFF, 0x30, 0xE7, 0x30, 0xC3, 0x30, 0xC3, 0x38, 0xC3, 0x3C, 0xC3, 0x1E, 0xE7, 0x0F, 0xFF, 0x07, 0xFE, 0x03, 0xFC, 0x00}, // Code for char 9
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x1C, 0x70, 0x1C, 0x70, 0x1C, 0x70, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // Code for char :
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x9C, 0x70, 0xFC, 0x70, 0xFC, 0x70, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // Code for char ;
{0x00, 0x00, 0x00, 0x00, 0xC0, 0x00, 0xE0, 0x01, 0xF0, 0x03, 0xF8, 0x07, 0x3C, 0x0F, 0x1E, 0x1E, 0x0F, 0x3C, 0x07, 0x38, 0x03, 0x30, 0x00, 0x00, 0x00, 0x00}, // Code for char <
{0x00, 0x00, 0x00, 0x00, 0x60, 0x06, 0x60, 0x06, 0x60, 0x06, 0x60, 0x06, 0x60, 0x06, 0x60, 0x06, 0x60, 0x06, 0x60, 0x06, 0x60, 0x06, 0x60, 0x06, 0x00, 0x00}, // Code for char =
{0x00, 0x00, 0x00, 0x00, 0x03, 0x30, 0x07, 0x38, 0x0F, 0x3C, 0x1E, 0x1E, 0x3C, 0x0F, 0xF8, 0x07, 0xF0, 0x03, 0xE0, 0x01, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00}, // Code for char >
{0x00, 0x00, 0x1C, 0x00, 0x1E, 0x00, 0x1F, 0x00, 0x07, 0x00, 0x83, 0x37, 0xC3, 0x37, 0xE3, 0x37, 0xF7, 0x00, 0x7F, 0x00, 0x3E, 0x00, 0x1C, 0x00, 0x00, 0x00}, // Code for char ?
{0x00, 0x00, 0xF8, 0x0F, 0xFE, 0x1F, 0xFF, 0x1F, 0xF7, 0x3B, 0xFB, 0x37, 0xFB, 0x37, 0xFB, 0x37, 0xFB, 0x37, 0xFF, 0x37, 0xFF, 0x37, 0xFE, 0x03, 0xF8, 0x01}, // Code for char @
{0x00, 0x00, 0x00, 0x38, 0x00, 0x3F, 0xE0, 0x3F, 0xFC, 0x07, 0xFF, 0x06, 0x1F, 0x06, 0xFF, 0x06, 0xFC, 0x07, 0xE0, 0x3F, 0x00, 0x3F, 0x00, 0x38, 0x00, 0x00}, // Code for char A
{0x00, 0x00, 0xFF, 0x3F, 0xFF, 0x3F, 0xFF, 0x3F, 0xC3, 0x30, 0xC3, 0x30, 0xC3, 0x30, 0xE7, 0x30, 0xFF, 0x39, 0xFE, 0x3F, 0xBC, 0x1F, 0x00, 0x0F, 0x00, 0x00}, // Code for char B
{0x00, 0x00, 0xF0, 0x03, 0xFC, 0x0F, 0xFE, 0x1F, 0x0F, 0x3C, 0x07, 0x38, 0x03, 0x30, 0x03, 0x30, 0x07, 0x38, 0x0F, 0x3C, 0x0E, 0x1C, 0x0C, 0x0C, 0x00, 0x00}, // Code for char C
{0x00, 0x00, 0xFF, 0x3F, 0xFF, 0x3F, 0xFF, 0x3F, 0x03, 0x30, 0x03, 0x30, 0x03, 0x30, 0x07, 0x38, 0x0F, 0x3C, 0xFE, 0x1F, 0xFC, 0x0F, 0xF0, 0x03, 0x00, 0x00}, // Code for char D
{0x00, 0x00, 0xFF, 0x3F, 0xFF, 0x3F, 0xFF, 0x3F, 0xC3, 0x30, 0xC3, 0x30, 0xC3, 0x30, 0xC3, 0x30, 0xC3, 0x30, 0xC3, 0x30, 0x03, 0x30, 0x03, 0x30, 0x00, 0x00}, // Code for char E
{0x00, 0x00, 0xFF, 0x3F, 0xFF, 0x3F, 0xFF, 0x3F, 0xC3, 0x00, 0xC3, 0x00, 0xC3, 0x00, 0xC3, 0x00, 0xC3, 0x00, 0xC3, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00}, // Code for char F
{0x00, 0x00, 0xF0, 0x03, 0xFC, 0x0F, 0xFE, 0x1F, 0x0F, 0x3C, 0x07, 0x38, 0xC3, 0x30, 0xC3, 0x30, 0xC3, 0x30, 0xC7, 0x3F, 0xC7, 0x3F, 0xC6, 0x3F, 0x00, 0x00}, // Code for char G
{0x00, 0x00, 0xFF, 0x3F, 0xFF, 0x3F, 0xFF, 0x3F, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xFF, 0x3F, 0xFF, 0x3F, 0xFF, 0x3F, 0x00, 0x00}, // Code for char H
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x30, 0x03, 0x30, 0xFF, 0x3F, 0xFF, 0x3F, 0xFF, 0x3F, 0x03, 0x30, 0x03, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, // Code for char I
{0x00, 0x00, 0x00, 0x0E, 0x00, 0x1E, 0x00, 0x3E, 0x00, 0x38, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x38, 0xFF, 0x3F, 0xFF, 0x1F, 0xFF, 0x07, 0x00, 0x00}, // Code for char J
{0x00, 0x00, 0xFF, 0x3F, 0xFF, 0x3F, 0xFF, 0x3F, 0xE0, 0x01, 0xF0, 0x03, 0xF8, 0x07, 0x3C, 0x0F, 0x1E, 0x1E, 0x0F, 0x3C, 0x07, 0x38, 0x03, 0x30, 0x00, 0x00}, // Code for char K
{0x00, 0x00, 0xFF, 0x3F, 0xFF, 0x3F, 0xFF, 0x3F, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x00}, // Code for char L
{0x00, 0x00, 0xFF, 0x3F, 0xFF, 0x3F, 0xFF, 0x3F, 0x7E, 0x00, 0xF8, 0x01, 0xE0, 0x01, 0xF8, 0x01, 0x7E, 0x00, 0xFF, 0x3F, 0xFF, 0x3F, 0xFF, 0x3F, 0x00, 0x00}, // Code for char M
{0x00, 0x00, 0xFF, 0x3F, 0xFF, 0x3F, 0xFF, 0x3F, 0x3E, 0x00, 0xF8, 0x00, 0xF0, 0x03, 0xC0, 0x07, 0x00, 0x1F, 0xFF, 0x3F, 0xFF, 0x3F, 0xFF, 0x3F, 0x00, 0x00}, // Code for char N
{0x00, 0x00, 0xF0, 0x03, 0xFC, 0x0F, 0xFE, 0x1F, 0x0F, 0x3C, 0x07, 0x38, 0x03, 0x30, 0x07, 0x38, 0x0F, 0x3C, 0xFE, 0x1F, 0xFC, 0x0F, 0xF0, 0x03, 0x00, 0x00}, // Code for char O
{0x00, 0x00, 0xFF, 0x3F, 0xFF, 0x3F, 0xFF, 0x3F, 0x83, 0x01, 0x83, 0x01, 0x83, 0x01, 0x83, 0x01, 0xC7, 0x01, 0xFF, 0x01, 0xFE, 0x00, 0x7C, 0x00, 0x00, 0x00}, // Code for char P
{0x00, 0x00, 0xF0, 0x03, 0xFC, 0x0F, 0xFE, 0x1F, 0x0F, 0x3C, 0x07, 0x38, 0x03, 0x36, 0x07, 0x3E, 0x0F, 0x3E, 0xFE, 0x3F, 0xFC, 0x3F, 0xF0, 0x33, 0x00, 0x00}, // Code for char Q
{0x00, 0x00, 0xFF, 0x3F, 0xFF, 0x3F, 0xFF, 0x3F, 0x83, 0x01, 0x83, 0x03, 0x83, 0x07, 0x83, 0x0F, 0xC7, 0x1F, 0xFF, 0x3D, 0xFE, 0x38, 0x7C, 0x30, 0x00, 0x00}, // Code for char R
{0x00, 0x00, 0x3C, 0x0C, 0x7E, 0x1C, 0xFF, 0x3C, 0xE7, 0x38, 0xC3, 0x30, 0xC3, 0x30, 0xC3, 0x30, 0xC7, 0x39, 0xCF, 0x3F, 0x8E, 0x1F, 0x0C, 0x0F, 0x00, 0x00}, // Code for char S
{0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0xFF, 0x3F, 0xFF, 0x3F, 0xFF, 0x3F, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00}, // Code for char T
{0x00, 0x00, 0xFF, 0x07, 0xFF, 0x1F, 0xFF, 0x3F, 0x00, 0x38, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x38, 0xFF, 0x3F, 0xFF, 0x1F, 0xFF, 0x07, 0x00, 0x00}, // Code for char U
{0x00, 0x00, 0x07, 0x00, 0x3F, 0x00, 0xFF, 0x01, 0xF8, 0x0F, 0xC0, 0x3F, 0x00, 0x3E, 0xC0, 0x3F, 0xF8, 0x0F, 0xFF, 0x01, 0x3F, 0x00, 0x07, 0x00, 0x00, 0x00}, // Code for char V
{0x00, 0x00, 0xFF, 0x3F, 0xFF, 0x3F, 0xFF, 0x3F, 0x00, 0x1E, 0x80, 0x07, 0x80, 0x03, 0x80, 0x07, 0x00, 0x1E, 0xFF, 0x3F, 0xFF, 0x3F, 0xFF, 0x3F, 0x00, 0x00}, // Code for char W
{0x00, 0x00, 0x03, 0x30, 0x0F, 0x3C, 0x1F, 0x3E, 0x3C, 0x0F, 0xF0, 0x03, 0xE0, 0x01, 0xF0, 0x03, 0x3C, 0x0F, 0x1F, 0x3E, 0x0F, 0x3C, 0x03, 0x30, 0x00, 0x00}, // Code for char X
{0x00, 0x00, 0x03, 0x00, 0x0F, 0x00, 0x3F, 0x00, 0xFC, 0x00, 0xF0, 0x3F, 0xC0, 0x3F, 0xF0, 0x3F, 0xFC, 0x00, 0x3F, 0x00, 0x0F, 0x00, 0x03, 0x00, 0x00, 0x00}, // Code for char Y
{0x00, 0x00, 0x03, 0x30, 0x03, 0x3C, 0x03, 0x3E, 0x03, 0x3F, 0xC3, 0x33, 0xE3, 0x31, 0xF3, 0x30, 0x3F, 0x30, 0x1F, 0x30, 0x0F, 0x30, 0x03, 0x30, 0x00, 0x00}, // Code for char Z
};
/*******************************************************************************
* Function Definitions
*******************************************************************************/
/*
* This function initialize the oled
*/
cy_rslt_t oled_init(void)
{
cy_rslt_t result = CY_RSLT_SUCCESS;
/* Configuration to initialize the I2C block */
cyhal_i2c_cfg_t i2c_config = {
.is_slave = false,
.address = OLED_I2C_ADDRESS,
.frequencyhal_hz = 400000
};
/* Initialize and configure the I2C to use with the OLED display */
result = cyhal_i2c_init( &i2c_obj, CYBSP_I2C_SDA,
CYBSP_I2C_SCL, NULL);
CY_ASSERT(result == CY_RSLT_SUCCESS);
printf("I2C Master init done!\r\n");
result = cyhal_i2c_configure(&i2c_obj, &i2c_config);
CY_ASSERT(result == CY_RSLT_SUCCESS);
printf("I2C Master config done!\r\n");
/* Initialize the OLED display */
result = mtb_ssd1306_init_i2c(&i2c_obj);
CY_ASSERT(result == CY_RSLT_SUCCESS);
mtb_ssd1306_write_command_byte(SSD1309_DISPLAYOFF);
mtb_ssd1306_write_command_byte(SSD1309_SETDISPLAYCLOCKDIV);
mtb_ssd1306_write_command_byte(0x80);
mtb_ssd1306_write_command_byte(SSD1309_SETMULTIPLEX);
mtb_ssd1306_write_command_byte(SSD1309_LCDHEIGHT-2);
mtb_ssd1306_write_command_byte(SSD1309_SETDISPLAYOFFSET);
mtb_ssd1306_write_command_byte(0x00);
mtb_ssd1306_write_command_byte(SSD1309_SETSTARTLINE);
mtb_ssd1306_write_command_byte(SSD1309_CHARGEPUMP);
mtb_ssd1306_write_command_byte(0x14);
mtb_ssd1306_write_command_byte(SSD1309_MEMORYMODE);
mtb_ssd1306_write_command_byte(0x00);
mtb_ssd1306_write_command_byte(SSD1309_SEGREMAP | 0x1);
mtb_ssd1306_write_command_byte(SSD1309_COMSCANDEC);
mtb_ssd1306_write_command_byte(SSD1309_SETCOMPINS);
mtb_ssd1306_write_command_byte(0x12);
mtb_ssd1306_write_command_byte(SSD1309_SETCONTRAST);
mtb_ssd1306_write_command_byte(0x7F);
mtb_ssd1306_write_command_byte(SSD1309_SETPRECHARGE);
mtb_ssd1306_write_command_byte(0xF1);
mtb_ssd1306_write_command_byte(0x40);
mtb_ssd1306_write_command_byte(SSD1309_DISPLAY_RAM);
mtb_ssd1306_write_command_byte(SSD1309_DISPLAY_NORMAL);
mtb_ssd1306_write_command_byte(SSD1309_DEACTIVATE_SCROLL);
mtb_ssd1306_write_command_byte(SSD1309_DISPLAYON);
mtb_ssd1306_write_command_byte(SSD1309_COLUMNADDR);
mtb_ssd1306_write_command_byte(0x00);
mtb_ssd1306_write_command_byte(SSD1309_LCDWIDTH - 1);
mtb_ssd1306_write_command_byte(SSD1309_PAGEADDR);
mtb_ssd1306_write_command_byte(0x00);
mtb_ssd1306_write_command_byte(0x07);
return result;
}
/*
* This function prints the oled default values
*/
void oled_init_screen(void)
{
oled_printLargeText(0, 8,"LELR DEMO");
oled_printText(2, 0,"------------CYW20829--");
#ifdef USE_S8_DEFAULT
oled_printText(3, 5,"CODE = S8");
#else
oled_printText(3, 5,"CODE = S2");
#endif
oled_printText(4, 5,"RSSI = ---");
oled_printText(5, 5,"DATA LEN = 0");
oled_printText(6, 5,"TIMER COUNT = 0");
oled_printText(7, 5,"CONN STATUS = 0");
}
/*
* This function clears the oled screen
*/
void oled_clear_screen(void)
{
memset(txBuff,0, PACKET_SIZE + 1);
txBuff[0] = 0x40;
cyhal_i2c_master_write(&i2c_obj, I2C_SLAVE_ADDR,txBuff, PACKET_SIZE, 0, true);
cyhal_i2c_master_write(&i2c_obj, I2C_SLAVE_ADDR,txBuff, PACKET_SIZE, 0, true);
cyhal_i2c_master_write(&i2c_obj, I2C_SLAVE_ADDR,txBuff, PACKET_SIZE, 0, true);
cyhal_i2c_master_write(&i2c_obj, I2C_SLAVE_ADDR,txBuff, PACKET_SIZE, 0, true);
cyhal_i2c_master_write(&i2c_obj, I2C_SLAVE_ADDR,txBuff, PACKET_SIZE, 0, true);
cyhal_i2c_master_write(&i2c_obj, I2C_SLAVE_ADDR,txBuff, PACKET_SIZE, 0, true);
cyhal_i2c_master_write(&i2c_obj, I2C_SLAVE_ADDR,txBuff, PACKET_SIZE, 0, true);
cyhal_i2c_master_write(&i2c_obj, I2C_SLAVE_ADDR,txBuff, PACKET_SIZE, 0, true);
}
/*
* This is function prints default text strings
*/
void oled_printText(uint8_t line, uint8_t x, char data[])
{
uint8_t i,j,len,x_max;
len =strlen((const char*) data);
if( line < DISP_MAX_LINE){
if((x + len*FONT5x8_CHAR_WIDTH) > SSD1309_LCDWIDTH -1 ){
x_max = SSD1309_LCDWIDTH - 1;
}
else
{
x_max = x + len*FONT5x8_CHAR_WIDTH;
}
memset(txBuff, 0, PACKET_SIZE + 1);
mtb_ssd1306_write_command_byte(SSD1309_COLUMNADDR);
mtb_ssd1306_write_command_byte(x);
mtb_ssd1306_write_command_byte(x_max);
mtb_ssd1306_write_command_byte(SSD1309_PAGEADDR);
mtb_ssd1306_write_command_byte(line);
mtb_ssd1306_write_command_byte(line);
for(j=0;j<len;j++){
for(i=0;i<FONT5x8_CHAR_WIDTH-1;i++){
txBuff[j*FONT5x8_CHAR_WIDTH + i ] = font5x8[data[j]-32][i];
}
}
mtb_ssd1306_write_data_stream(txBuff, x_max-x);
}
}
/*
* This is function prints large text strings
*/
void oled_printLargeText(uint8_t line, uint8_t x, char data[]){
uint8_t i,j,k,len,x_max;
len =strlen((const char*) data);
if( line < (DISP_MAX_LINE -1)){
if((x + len*FONT12x16_CHAR_WIDTH) > SSD1309_LCDWIDTH -1){
x_max = SSD1309_LCDWIDTH - 1;
}
else
{
x_max = x + len*FONT12x16_CHAR_WIDTH;
}
memset(txBuff, 0, PACKET_SIZE + 1 );
mtb_ssd1306_write_command_byte(SSD1309_COLUMNADDR);
mtb_ssd1306_write_command_byte(x);
mtb_ssd1306_write_command_byte(x_max);
mtb_ssd1306_write_command_byte(SSD1309_PAGEADDR);
mtb_ssd1306_write_command_byte(line);
mtb_ssd1306_write_command_byte(line);
for(j=0;j<len;j++){
for(i=0,k=0;i <(FONT12x16_CHAR_WIDTH*2);i=i+2,k++){
txBuff[j*FONT12x16_CHAR_WIDTH + k] = font12x16[data[j]-32][i];
}
}
mtb_ssd1306_write_data_stream(txBuff, x_max-x);
mtb_ssd1306_write_command_byte(SSD1309_COLUMNADDR);
mtb_ssd1306_write_command_byte(x);
mtb_ssd1306_write_command_byte(x_max);
mtb_ssd1306_write_command_byte(SSD1309_PAGEADDR);
mtb_ssd1306_write_command_byte(line+1);
mtb_ssd1306_write_command_byte(line+1);
for(j=0;j<len;j++){
for(i=1,k=0;i<(FONT12x16_CHAR_WIDTH*2);i=i+2,k++){
txBuff[j*FONT12x16_CHAR_WIDTH + k] = font12x16[data[j]-32][i];
}
}
mtb_ssd1306_write_data_stream(txBuff, x_max-x);
}
}
/* END OF FILE [] */