Started the cleaning process, unsuled LCD functions are deleted

master
kerem yollu 2 years ago
parent 5e21945627
commit 5de8884257

@ -11,6 +11,7 @@ set(PL "c")
# Setting the used directory locations
####################################################################################################
# Location of the project : It is defaulted to one Higher than the KED Directory :TODO: Shall we let
# the user define it weherever he wants it ?
set(PROJECT_DIR ${CMAKE_SOURCE_DIR}/..)
@ -81,10 +82,7 @@ set(EXECUTABLE ${PROJECT_NAME})
# SUBDIRECTORIES Will add the given folders to the porject an check for CmakeLists.txt
####################################################################################################
include(${CSL_DEFS})
add_subdirectory(libraries)
add_subdirectory(csl)
add_subdirectory(drivers)
add_subdirectory(peripherals)
####################################################################################################
# Sartupt uCode Definition

@ -313,8 +313,6 @@ typedef enum {
intTypeEND
}intrType_t;
uint32_t intHandlerList[intTypeEND]={
0,0,0,0,0,0,0,0,0,0};
static const uint8_t interruptTypeIndexList[intTypeEND] =
{

@ -1,6 +1,7 @@
#include "interrupt.h"
static void defaultHandler(){};
//static void defaultHandler(){};
static uint32_t intHandlerList[intTypeEND]={0,0,0,0,0,0,0,0,0,0};
// pointers to dedicated interrupt handlers

@ -13,7 +13,7 @@ set(CMAKE_SYSTEM_PROCESSOR arm)
set(CMAKE_CROSSCOMPILING TRUE)
set(LINKER ${CMAKE_SOURCE_DIR}/csl/stm32f042/startup/STM32F042K6Tx_FLASH.ld)
set(CSL_USED ${CMAKE_SOURCE_DIR}/csl/stm32f042)
#set(CSL_USED ${CMAKE_SOURCE_DIR}/csl/stm32f042)
####################################################################################################
#VARIABLES : defined by user
####################################################################################################

@ -105,14 +105,14 @@ uint8_t lcd_oled_clear()
uint8_t lcd_oled_display()
{
ssd1306_i2c_command(&i2c_device,SSD1306_COLUMNADDR);
ssd1306_i2c_command(&i2c_device,0); // Column start address (0 = reset)
ssd1306_i2c_command(&i2c_device,LCD_OLED_SIZE_X - 1); // Column end address (127
ssd1306_i2c_send_command(&i2c_device,SSD1306_COLUMNADDR);
ssd1306_i2c_send_command(&i2c_device,0); // Column start address (0 = reset)
ssd1306_i2c_send_command(&i2c_device,LCD_OLED_SIZE_X - 1); // Column end address (127
// = reset)
ssd1306_i2c_command(&i2c_device,SSD1306_PAGEADDR);
ssd1306_i2c_command(&i2c_device,0); // Page start address (0 = reset)
ssd1306_i2c_command(&i2c_device,7); // Page end address
ssd1306_i2c_send_command(&i2c_device,SSD1306_PAGEADDR);
ssd1306_i2c_send_command(&i2c_device,0); // Page start address (0 = reset)
ssd1306_i2c_send_command(&i2c_device,7); // Page end address
uint8_t i2cDataLenght = 1; // Co = 0, D/C = 0
uint16_t address = SSD1306_I2C_ADDRESS; // Co = 0, D/C = 0
@ -131,6 +131,7 @@ uint8_t lcd_oled_display()
uint8_t reg = 0x40;
i2c_write(&i2c_device, &address, &reg, &display_buffer, &i2cDataLenght);
*/
return 1;
}
void lcd_oled_print_char(uint16_t x, uint16_t y, uint8_t c, uint8_t color)

@ -39,154 +39,20 @@ All text above, and the splash screen below must be included in any redistributi
int8_t cursor_y = 0;
int8_t cursor_x = 0;
// the memory buffer for the LCD. Displays Adafruit logo
uint8_t buffer[SSD1306_LCDWIDTH * SSD1306_LCDHEIGHT / 8] = {
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, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80,
0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x80, 0x80, 0xC0, 0xC0, 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, 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, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xF8, 0xE0,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x80, 0x80, 0x80,
0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80,
0x80, 0x80, 0x00, 0xFF,
0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00,
0x80, 0x80, 0x00, 0x00,
0x80, 0xFF, 0xFF, 0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x80, 0x80, 0x80,
0x80, 0x00, 0x80, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x8C, 0x8E, 0x84,
0x00, 0x00, 0x80, 0xF8,
0xF8, 0xF8, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xE0, 0xE0, 0xC0, 0x80,
0x00, 0xE0, 0xFC, 0xFE, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE,
0xFF, 0xC7, 0x01, 0x01,
0x01, 0x01, 0x83, 0xFF, 0xFF, 0x00, 0x00, 0x7C, 0xFE, 0xC7, 0x01, 0x01,
0x01, 0x01, 0x83, 0xFF,
0xFF, 0xFF, 0x00, 0x38, 0xFE, 0xC7, 0x83, 0x01, 0x01, 0x01, 0x83, 0xC7,
0xFF, 0xFF, 0x00, 0x00,
0x01, 0xFF, 0xFF, 0x01, 0x01, 0x00, 0xFF, 0xFF, 0x07, 0x01, 0x01, 0x01,
0x00, 0x00, 0x7F, 0xFF,
0x80, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0xFF, 0xFF, 0xFF,
0x00, 0x00, 0x01, 0xFF,
0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x03, 0x0F, 0x3F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xE7, 0xC7, 0xC7, 0x8F,
0x8F, 0x9F, 0xBF, 0xFF, 0xFF, 0xC3, 0xC0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFC, 0xFC, 0xFC,
0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xF8, 0xF8, 0xF0, 0xF0, 0xE0, 0xC0, 0x00,
0x01, 0x03, 0x03, 0x03,
0x03, 0x03, 0x01, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03,
0x03, 0x03, 0x01, 0x01,
0x03, 0x01, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01,
0x03, 0x03, 0x00, 0x00,
0x00, 0x03, 0x03, 0x00, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01,
0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x01, 0x03, 0x01,
0x00, 0x00, 0x00, 0x03,
0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF9, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0x3F, 0x1F, 0x0F,
0x87, 0xC7, 0xF7, 0xFF, 0xFF, 0x1F, 0x1F, 0x3D, 0xFC, 0xF8, 0xF8, 0xF8,
0xF8, 0x7C, 0x7D, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x0F, 0x07, 0x00,
0x30, 0x30, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xE0, 0xC0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0xC0, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0x7F, 0x7F, 0x3F, 0x1F,
0x0F, 0x07, 0x1F, 0x7F, 0xFF, 0xFF, 0xF8, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFE, 0xF8, 0xE0,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xFE, 0xFE, 0x00, 0x00,
0x00, 0xFC, 0xFE, 0xFC, 0x0C, 0x06, 0x06, 0x0E, 0xFC, 0xF8, 0x00, 0x00,
0xF0, 0xF8, 0x1C, 0x0E,
0x06, 0x06, 0x06, 0x0C, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFE, 0xFE, 0x00,
0x00, 0x00, 0x00, 0xFC,
0xFE, 0xFC, 0x00, 0x18, 0x3C, 0x7E, 0x66, 0xE6, 0xCE, 0x84, 0x00, 0x00,
0x06, 0xFF, 0xFF, 0x06,
0x06, 0xFC, 0xFE, 0xFC, 0x0C, 0x06, 0x06, 0x06, 0x00, 0x00, 0xFE, 0xFE,
0x00, 0x00, 0xC0, 0xF8,
0xFC, 0x4E, 0x46, 0x46, 0x46, 0x4E, 0x7C, 0x78, 0x40, 0x18, 0x3C, 0x76,
0xE6, 0xCE, 0xCC, 0x80,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0x0F, 0x1F, 0x1F, 0x3F, 0x3F, 0x3F,
0x3F, 0x1F, 0x0F, 0x03,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0F, 0x0F, 0x00, 0x00,
0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00,
0x03, 0x07, 0x0E, 0x0C,
0x18, 0x18, 0x0C, 0x06, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x01, 0x0F, 0x0E,
0x0C, 0x18, 0x0C, 0x0F,
0x07, 0x01, 0x00, 0x04, 0x0E, 0x0C, 0x18, 0x0C, 0x0F, 0x07, 0x00, 0x00,
0x00, 0x0F, 0x0F, 0x00,
0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F,
0x00, 0x00, 0x00, 0x07,
0x07, 0x0C, 0x0C, 0x18, 0x1C, 0x0C, 0x06, 0x06, 0x00, 0x04, 0x0E, 0x0C,
0x18, 0x0C, 0x0F, 0x07,
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, 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, 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, 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, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
};
int8_t _vccstate;
int16_t i2cd;
#define ssd1306_swap(a, b) { int16_t t = a; a = b; b = t; }
//Section : 10.1.12 Set Display ON/OFF (AEh/AFh) | Page 37
void ssd1306_i2c_set_display_off(i2c_t *i2c_dev)
{
ssd1306_i2c_command(i2c_dev,SSD1306_DISPLAYOFF);
ssd1306_i2c_send_command(i2c_dev,SSD1306_DISPLAYOFF);
}
//Section : 10.1.12 Set Display ON/OFF (AEh/AFh) | Page 37
void ssd1306_i2c_set_display_on(i2c_t *i2c_dev)
{
ssd1306_i2c_command(i2c_dev,SSD1306_DISPLAYON);
ssd1306_i2c_send_command(i2c_dev,SSD1306_DISPLAYON);
}
// TODO: Find a ferq Calculator
@ -204,29 +70,29 @@ void ssd1306_i2c_set_display_clkDiv_oscFreq(i2c_t *i2c_dev, uint8_t clockDivider
}
}
ssd1306_i2c_command(i2c_dev,SSD1306_SETDISPLAYCLOCKDIV); // 0xD5
ssd1306_i2c_command(i2c_dev,value); // the suggested ratio 0x80
ssd1306_i2c_send_command(i2c_dev,SSD1306_SETDISPLAYCLOCKDIV); // 0xD5
ssd1306_i2c_send_command(i2c_dev,value); // the suggested ratio 0x80
}
// Section : 10.1.11 Set Multiplex Ratio (A8h) | Page : 37
void ssd1306_i2c_set_multiplex_ratio(i2c_t *i2c_dev, uint8_t ratio)
{
ssd1306_i2c_command(i2c_dev,SSD1306_SETMULTIPLEX); // 0xA8
ssd1306_i2c_command(i2c_dev,ratio);
ssd1306_i2c_send_command(i2c_dev,SSD1306_SETMULTIPLEX); // 0xA8
ssd1306_i2c_send_command(i2c_dev,ratio);
}
// Section : 10.1.15 Set Display Offset (D3h) | Page : 37
void ssd1306_i2c_set_display_offset(i2c_t *i2c_dev, uint8_t offset)
{
ssd1306_i2c_command(i2c_dev,SSD1306_SETDISPLAYOFFSET); // 0xD3
ssd1306_i2c_command(i2c_dev,offset);
ssd1306_i2c_send_command(i2c_dev,SSD1306_SETDISPLAYOFFSET); // 0xD3
ssd1306_i2c_send_command(i2c_dev,offset);
}
// Section : 10.1.13 Set Page Start Address for Page Addressing Mode (B0h~B7h) | Page : 37
void ssd1306_i2c_set_display_start_line(i2c_t *i2c_dev, uint8_t start)
{
if(start <= 7)
{
ssd1306_i2c_command(i2c_dev,SSD1306_SETSTARTLINE | start);
ssd1306_i2c_send_command(i2c_dev,SSD1306_SETSTARTLINE | start);
}
}
@ -234,19 +100,19 @@ void ssd1306_i2c_set_display_start_line(i2c_t *i2c_dev, uint8_t start)
// Section : 2.1 Command Table for Charge Bump Setting | Page : 60
void ssd1306_i2c_set_chage_pump(i2c_t *i2c_dev, uint8_t voltageSource)
{
ssd1306_i2c_command(i2c_dev,SSD1306_CHARGEPUMP); // 0x8D
ssd1306_i2c_send_command(i2c_dev,SSD1306_CHARGEPUMP); // 0x8D
if (voltageSource == SSD1306_EXTERNALVCC) {
ssd1306_i2c_command(i2c_dev,0x10);
ssd1306_i2c_send_command(i2c_dev,0x10);
} else {
ssd1306_i2c_command(i2c_dev,SSD1306_ENABLE_CHAGE_PUMP);
ssd1306_i2c_send_command(i2c_dev,SSD1306_ENABLE_CHAGE_PUMP);
}
}
// Section :10.1.3 Set Memory Addressing Mode (20h) | Page : 34
void ssd1306_i2c_set_memory_addressing_mode(i2c_t *i2c_dev, uint8_t mode)
{
ssd1306_i2c_command(i2c_dev,SSD1306_MEMORYMODE);
ssd1306_i2c_command(i2c_dev,mode);
ssd1306_i2c_send_command(i2c_dev,SSD1306_MEMORYMODE);
ssd1306_i2c_send_command(i2c_dev,mode);
}
// TODO : Not very clear what this functionality does :S
@ -255,11 +121,11 @@ void ssd1306_i2c_set_segment_remap(i2c_t *i2c_dev, uint8_t enable)
{
if(enable)
{
ssd1306_i2c_command(i2c_dev,SSD1306_SEGREMAP | 0x1);
ssd1306_i2c_send_command(i2c_dev,SSD1306_SEGREMAP | 0x1);
}
else
{
ssd1306_i2c_command(i2c_dev,SSD1306_SEGREMAP | 0x0);
ssd1306_i2c_send_command(i2c_dev,SSD1306_SEGREMAP | 0x0);
}
}
// Section : 10.1.14 Set COM Output Scan Direction (C0h/C8h) | Page 37
@ -267,48 +133,48 @@ void ssd1306_i2c_set_com_scan_direction(i2c_t *i2c_dev, uint8_t incremental)
{
if(incremental)
{
ssd1306_i2c_command(i2c_dev,SSD1306_COMSCANINC);
ssd1306_i2c_send_command(i2c_dev,SSD1306_COMSCANINC);
}
else
{
ssd1306_i2c_command(i2c_dev,SSD1306_COMSCANDEC);
ssd1306_i2c_send_command(i2c_dev,SSD1306_COMSCANDEC);
}
}
// Section : 10.1.18 Set COM Pins Hardware Configuration (DAh) | Page : 40
void ssd1306_i2c_set_com_pins(i2c_t *i2c_dev, uint8_t alignment)
{
ssd1306_i2c_command(i2c_dev,SSD1306_SETCOMPINS);
ssd1306_i2c_command(i2c_dev,alignment);
ssd1306_i2c_send_command(i2c_dev,SSD1306_SETCOMPINS);
ssd1306_i2c_send_command(i2c_dev,alignment);
}
void ssd1306_i2c_set_contrast(i2c_t *i2c_dev, uint8_t contrast)
{
ssd1306_i2c_command(i2c_dev,SSD1306_SETCONTRAST); // 0x81
ssd1306_i2c_command(i2c_dev,contrast);
ssd1306_i2c_send_command(i2c_dev,SSD1306_SETCONTRAST); // 0x81
ssd1306_i2c_send_command(i2c_dev,contrast);
}
void ssd1306_i2c_set_prechage_period(i2c_t *i2c_dev, uint8_t period)
{
ssd1306_i2c_command(i2c_dev,SSD1306_SETPRECHARGE); // 0xd9
ssd1306_i2c_command(i2c_dev,period);
ssd1306_i2c_send_command(i2c_dev,SSD1306_SETPRECHARGE); // 0xd9
ssd1306_i2c_send_command(i2c_dev,period);
}
void ssd1306_i2c_set_com_deselect_level(i2c_t *i2c_dev, uint8_t voltageLevel)
{
ssd1306_i2c_command(i2c_dev,SSD1306_SETVCOMDETECT); // 0xDB
ssd1306_i2c_command(i2c_dev,voltageLevel);
ssd1306_i2c_send_command(i2c_dev,SSD1306_SETVCOMDETECT); // 0xDB
ssd1306_i2c_send_command(i2c_dev,voltageLevel);
}
void ssd1306_i2c_set_display_entire_on(i2c_t *i2c_dev, uint8_t resumeOrForce)
{
if(resumeOrForce = SSD1306_DISPLAYALLON_RESUME)
if(resumeOrForce == SSD1306_DISPLAYALLON_RESUME)
{
ssd1306_i2c_command(i2c_dev,SSD1306_DISPLAYALLON_RESUME); // 0xA4
ssd1306_i2c_send_command(i2c_dev,SSD1306_DISPLAYALLON_RESUME); // 0xA4
}
else
{
ssd1306_i2c_command(i2c_dev,SSD1306_DISPLAYALLON); // 0xA4
ssd1306_i2c_send_command(i2c_dev,SSD1306_DISPLAYALLON); // 0xA4
}
}
@ -317,11 +183,11 @@ void ssd1306_i2c_set_display_invert_pixel(i2c_t *i2c_dev, uint8_t inverted)
{
if(inverted)
{
ssd1306_i2c_command(i2c_dev,SSD1306_INVERTDISPLAY); // 0xA6
ssd1306_i2c_send_command(i2c_dev,SSD1306_INVERTDISPLAY); // 0xA6
}
else
{
ssd1306_i2c_command(i2c_dev,SSD1306_NORMALDISPLAY); // 0xA6
ssd1306_i2c_send_command(i2c_dev,SSD1306_NORMALDISPLAY); // 0xA6
}
}
@ -329,28 +195,19 @@ void ssd1306_i2c_set_scroll(i2c_t *i2c_dev, uint8_t onOff)
{
if(onOff)
{
ssd1306_i2c_command(i2c_dev,SSD1306_ACTIVATE_SCROLL);
ssd1306_i2c_send_command(i2c_dev,SSD1306_ACTIVATE_SCROLL);
}
else
{
ssd1306_i2c_command(i2c_dev,SSD1306_DEACTIVATE_SCROLL);
ssd1306_i2c_send_command(i2c_dev,SSD1306_DEACTIVATE_SCROLL);
}
}
void ssd1306_invertDisplay(i2c_t *i2c_dev, uint16_t i)
{
if (i) {
ssd1306_i2c_command(i2c_dev,SSD1306_INVERTDISPLAY);
} else {
ssd1306_i2c_command(i2c_dev,SSD1306_NORMALDISPLAY);
}
}
void ssd1306_i2c_command(i2c_t *i2c_dev,uint16_t c)
void ssd1306_i2c_send_command(i2c_t *i2c_dev,uint8_t c)
{
// I2C
uint16_t control = 0x00; // Co = 0, D/C = 0
uint8_t control = 0x00; // Co = 0, D/C = 0
uint8_t i2cDataLenght = 1; // Co = 0, D/C = 0
uint16_t address = SSD1306_I2C_ADDRESS; // Co = 0, D/C = 0
i2c_write(i2c_dev, &address, &control, &c, &i2cDataLenght);
@ -363,14 +220,14 @@ void ssd1306_i2c_command(i2c_t *i2c_dev,uint16_t c)
// ssd1306_scrollright(0x00, 0x0F)
void ssd1306_startscrollright(i2c_t *i2c_dev, uint16_t start, uint16_t stop)
{
ssd1306_i2c_command(i2c_dev,SSD1306_RIGHT_HORIZONTAL_SCROLL);
ssd1306_i2c_command(i2c_dev,0X00);
ssd1306_i2c_command(i2c_dev,start);
ssd1306_i2c_command(i2c_dev,0X00);
ssd1306_i2c_command(i2c_dev,stop);
ssd1306_i2c_command(i2c_dev,0X00);
ssd1306_i2c_command(i2c_dev,0XFF);
ssd1306_i2c_command(i2c_dev,SSD1306_ACTIVATE_SCROLL);
ssd1306_i2c_send_command(i2c_dev,SSD1306_RIGHT_HORIZONTAL_SCROLL);
ssd1306_i2c_send_command(i2c_dev,0X00);
ssd1306_i2c_send_command(i2c_dev,start);
ssd1306_i2c_send_command(i2c_dev,0X00);
ssd1306_i2c_send_command(i2c_dev,stop);
ssd1306_i2c_send_command(i2c_dev,0X00);
ssd1306_i2c_send_command(i2c_dev,0XFF);
ssd1306_i2c_send_command(i2c_dev,SSD1306_ACTIVATE_SCROLL);
}
// startscrollleft
@ -379,14 +236,14 @@ void ssd1306_startscrollright(i2c_t *i2c_dev, uint16_t start, uint16_t stop)
// ssd1306_scrollright(0x00, 0x0F)
void ssd1306_startscrollleft(i2c_t *i2c_dev,uint16_t start, uint16_t stop)
{
ssd1306_i2c_command(i2c_dev,SSD1306_LEFT_HORIZONTAL_SCROLL);
ssd1306_i2c_command(i2c_dev,0X00);
ssd1306_i2c_command(i2c_dev,start);
ssd1306_i2c_command(i2c_dev,0X00);
ssd1306_i2c_command(i2c_dev,stop);
ssd1306_i2c_command(i2c_dev,0X00);
ssd1306_i2c_command(i2c_dev,0XFF);
ssd1306_i2c_command(i2c_dev,SSD1306_ACTIVATE_SCROLL);
ssd1306_i2c_send_command(i2c_dev,SSD1306_LEFT_HORIZONTAL_SCROLL);
ssd1306_i2c_send_command(i2c_dev,0X00);
ssd1306_i2c_send_command(i2c_dev,start);
ssd1306_i2c_send_command(i2c_dev,0X00);
ssd1306_i2c_send_command(i2c_dev,stop);
ssd1306_i2c_send_command(i2c_dev,0X00);
ssd1306_i2c_send_command(i2c_dev,0XFF);
ssd1306_i2c_send_command(i2c_dev,SSD1306_ACTIVATE_SCROLL);
}
// startscrolldiagright
@ -395,16 +252,16 @@ void ssd1306_startscrollleft(i2c_t *i2c_dev,uint16_t start, uint16_t stop)
// ssd1306_scrollright(0x00, 0x0F)
void ssd1306_startscrolldiagright(i2c_t *i2c_dev, uint16_t start, uint16_t stop)
{
ssd1306_i2c_command(i2c_dev,SSD1306_SET_VERTICAL_SCROLL_AREA);
ssd1306_i2c_command(i2c_dev,0X00);
ssd1306_i2c_command(i2c_dev,SSD1306_LCDHEIGHT);
ssd1306_i2c_command(i2c_dev,SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL);
ssd1306_i2c_command(i2c_dev,0X00);
ssd1306_i2c_command(i2c_dev,start);
ssd1306_i2c_command(i2c_dev,0X00);
ssd1306_i2c_command(i2c_dev,stop);
ssd1306_i2c_command(i2c_dev,0X01);
ssd1306_i2c_command(i2c_dev,SSD1306_ACTIVATE_SCROLL);
ssd1306_i2c_send_command(i2c_dev,SSD1306_SET_VERTICAL_SCROLL_AREA);
ssd1306_i2c_send_command(i2c_dev,0X00);
ssd1306_i2c_send_command(i2c_dev,SSD1306_LCDHEIGHT);
ssd1306_i2c_send_command(i2c_dev,SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL);
ssd1306_i2c_send_command(i2c_dev,0X00);
ssd1306_i2c_send_command(i2c_dev,start);
ssd1306_i2c_send_command(i2c_dev,0X00);
ssd1306_i2c_send_command(i2c_dev,stop);
ssd1306_i2c_send_command(i2c_dev,0X01);
ssd1306_i2c_send_command(i2c_dev,SSD1306_ACTIVATE_SCROLL);
}
// startscrolldiagleft
@ -413,374 +270,18 @@ void ssd1306_startscrolldiagright(i2c_t *i2c_dev, uint16_t start, uint16_t stop)
// ssd1306_scrollright(0x00, 0x0F)
void ssd1306_startscrolldiagleft(i2c_t *i2c_dev, uint16_t start, uint16_t stop)
{
ssd1306_i2c_command(i2c_dev,SSD1306_SET_VERTICAL_SCROLL_AREA);
ssd1306_i2c_command(i2c_dev,0X00);
ssd1306_i2c_command(i2c_dev,SSD1306_LCDHEIGHT);
ssd1306_i2c_command(i2c_dev,SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL);
ssd1306_i2c_command(i2c_dev,0X00);
ssd1306_i2c_command(i2c_dev,start);
ssd1306_i2c_command(i2c_dev,0X00);
ssd1306_i2c_command(i2c_dev,stop);
ssd1306_i2c_command(i2c_dev,0X01);
ssd1306_i2c_command(i2c_dev,SSD1306_ACTIVATE_SCROLL);
}
void ssd1306_stopscroll(i2c_t *i2c_dev)
{
ssd1306_i2c_command(i2c_dev,SSD1306_DEACTIVATE_SCROLL);
}
void ssd1306_drawFastHLineInternal(int16_t x, int16_t y, int16_t w, uint16_t color)
{
// Do bounds/limit checks
if (y < 0 || y >= HEIGHT) {
return;
}
// make sure we don't try to draw below 0
if (x < 0) {
w += x;
x = 0;
}
// make sure we don't go off the edge of the display
if ((x + w) > WIDTH) {
w = (WIDTH - x);
}
// if our width is now negative, punt
if (w <= 0) {
return;
}
// set up the pointer for movement through the buffer
uint16_t *pBuf = buffer;
// adjust the buffer pointer for the current row
pBuf += ((y / 8) * SSD1306_LCDWIDTH);
// and offset x columns in
pBuf += x;
uint16_t mask = 1 << (y & 7);
switch (color) {
case WHITE:
while (w--) {
*pBuf++ |= mask;
};
break;
case BLACK:
mask = ~mask;
while (w--) {
*pBuf++ &= mask;
};
break;
case INVERSE:
while (w--) {
*pBuf++ ^= mask;
};
break;
}
}
void ssd1306_drawFastVLineInternal(int16_t x, int16_t __y, int16_t __h, uint16_t color)
{
// do nothing if we're off the left or right side of the screen
if (x < 0 || x >= WIDTH) {
return;
}
// make sure we don't try to draw below 0
if (__y < 0) {
// __y is negative, this will subtract enough from __h to account
// for __y being 0
__h += __y;
__y = 0;
}
// make sure we don't go past the height of the display
if ((__y + __h) > HEIGHT) {
__h = (HEIGHT - __y);
}
// if our height is now negative, punt
if (__h <= 0) {
return;
}
// this display doesn't need ints for coordinates, use local byte
// registers for faster juggling
uint16_t y = __y;
uint16_t h = __h;
// set up the pointer for fast movement through the buffer
uint16_t *pBuf = buffer;
// adjust the buffer pointer for the current row
pBuf += ((y / 8) * SSD1306_LCDWIDTH);
// and offset x columns in
pBuf += x;
// do the first partial byte, if necessary - this requires some
// masking
uint16_t mod = (y & 7);
if (mod) {
// mask off the high n bits we want to set
mod = 8 - mod;
// note - lookup table results in a nearly 10% performance
// improvement in fill* functions
// register uint16_t mask = ~(0xFF >> (mod));
static uint16_t premask[8] =
{ 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE };
uint16_t mask = premask[mod];
// adjust the mask if we're not going to reach the end of this
// byte
if (h < mod) {
mask &= (0XFF >> (mod - h));
}
switch (color) {
case WHITE:
*pBuf |= mask;
break;
case BLACK:
*pBuf &= ~mask;
break;
case INVERSE:
*pBuf ^= mask;
break;
}
// fast exit if we're done here!
if (h < mod) {
return;
}
h -= mod;
pBuf += SSD1306_LCDWIDTH;
}
// write solid bytes while we can - effectively doing 8 rows at a time
if (h >= 8) {
if (color == INVERSE) { // separate copy of the code so we don't
// impact performance of the black/white
// write version with an extra comparison
// per loop
do {
*pBuf = ~(*pBuf);
// adjust the buffer forward 8 rows worth of data
pBuf += SSD1306_LCDWIDTH;
// adjust h & y (there's got to be a faster way for me to
// do this, but this should still help a fair bit for now)
h -= 8;
}
while (h >= 8);
} else {
// store a local value to work with
register uint16_t val = (color == WHITE) ? 255 : 0;
do {
// write our value in
*pBuf = val;
// adjust the buffer forward 8 rows worth of data
pBuf += SSD1306_LCDWIDTH;
// adjust h & y (there's got to be a faster way for me to
// do this, but this should still help a fair bit for now)
h -= 8;
}
while (h >= 8);
}
}
// now do the final partial byte, if necessary
if (h) {
mod = h & 7;
// this time we want to mask the low bits of the byte, vs the high
// bits we did above
// register uint16_t mask = (1 << mod) - 1;
// note - lookup table results in a nearly 10% performance
// improvement in fill* functions
static uint16_t postmask[8] =
{ 0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F };
uint16_t mask = postmask[mod];
switch (color) {
case WHITE:
*pBuf |= mask;
break;
case BLACK:
*pBuf &= ~mask;
break;
case INVERSE:
*pBuf ^= mask;
break;
}
}
}
void ssd1306_drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color)
{
uint16_t bSwap = false;
switch (rotation) {
case 0:
// 0 degree rotation, do nothing
break;
case 1:
// 90 degree rotation, swap x & y for rotation, then invert x
bSwap = true;
ssd1306_swap(x, y);
x = WIDTH - x - 1;
break;
case 2:
// 180 degree rotation, invert x and y - then shift y around for
// height.
x = WIDTH - x - 1;
y = HEIGHT - y - 1;
x -= (w - 1);
break;
case 3:
// 270 degree rotation, swap x & y for rotation, then invert y and
// adjust y for w (not to become h)
bSwap = true;
ssd1306_swap(x, y);
y = HEIGHT - y - 1;
y -= (w - 1);
break;
}
if (bSwap) {
ssd1306_drawFastVLineInternal(x, y, w, color);
} else {
ssd1306_drawFastHLineInternal(x, y, w, color);
}
}
void ssd1306_drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color)
{
uint16_t bSwap = false;
switch (rotation) {
case 0:
break;
case 1:
// 90 degree rotation, swap x & y for rotation, then invert x and
// adjust x for h (now to become w)
bSwap = true;
ssd1306_swap(x, y);
x = WIDTH - x - 1;
x -= (h - 1);
break;
case 2:
// 180 degree rotation, invert x and y - then shift y around for
// height.
x = WIDTH - x - 1;
y = HEIGHT - y - 1;
y -= (h - 1);
break;
case 3:
// 270 degree rotation, swap x & y for rotation, then invert y
bSwap = true;
ssd1306_swap(x, y);
y = HEIGHT - y - 1;
break;
}
if (bSwap) {
ssd1306_drawFastHLineInternal(x, y, h, color);
} else {
ssd1306_drawFastVLineInternal(x, y, h, color);
}
ssd1306_i2c_send_command(i2c_dev,SSD1306_SET_VERTICAL_SCROLL_AREA);
ssd1306_i2c_send_command(i2c_dev,0X00);
ssd1306_i2c_send_command(i2c_dev,SSD1306_LCDHEIGHT);
ssd1306_i2c_send_command(i2c_dev,SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL);
ssd1306_i2c_send_command(i2c_dev,0X00);
ssd1306_i2c_send_command(i2c_dev,start);
ssd1306_i2c_send_command(i2c_dev,0X00);
ssd1306_i2c_send_command(i2c_dev,stop);
ssd1306_i2c_send_command(i2c_dev,0X01);
ssd1306_i2c_send_command(i2c_dev,SSD1306_ACTIVATE_SCROLL);
}
void ssd1306_fillRect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t fillcolor)
{
// Bounds check
if ((x >= WIDTH) || (y >= HEIGHT))
return;
// Y bounds check
if (y + h > HEIGHT) {
h = HEIGHT - y - 1;
}
// X bounds check
if (x + w > WIDTH) {
w = WIDTH - x - 1;
}
switch (rotation) {
case 1:
swap_values(x, y);
x = WIDTH - x - 1;
break;
case 2:
x = WIDTH - x - 1;
y = HEIGHT - y - 1;
break;
case 3:
swap_values(x, y);
y = HEIGHT - y - 1;
break;
}
int16_t i;
for (i = 0; i < h; i++)
ssd1306_drawFastHLine(x, y + i, w, fillcolor);
}
int16_t textsize = 1;
int16_t wrap = 1;
void ssd1306_setTextSize(int16_t s)
{
textsize = (s > 0) ? s : 1;
}
void ssd1306_write(int16_t c)
{
if (c == '\n') {
cursor_y += textsize * 8;
cursor_x = 0;
} else if (c == '\r') {
// skip em
} else {
ssd1306_drawChar(cursor_x, cursor_y, c, WHITE, textsize);
cursor_x += textsize * 6;
if (wrap && (cursor_x > (WIDTH - textsize * 6))) {
cursor_y += textsize * 8;
cursor_x = 0;
}
}
}
void ssd1306_drawString(int8_t *str)
{
int16_t i, end;
end = 5;
for (i = 0; i < end; i++)
ssd1306_write(str[i]);
}
// Draw a character
void ssd1306_drawChar(int16_t x, int16_t y, uint8_t c, int16_t color, int16_t size)
{
//Adapted and optimized for oled_lcd.c
}
// the most basic function, set a single pixel
void ssd1306_drawPixel(int16_t x, int16_t y, uint16_t color)
{
//Adapted and optimized for oled_lcd.c
}
// clear everything
void ssd1306_clearDisplay()
{
//Adapted and optimized for oled_lcd.c
}
// Init SSD1306
void ssd1306_begin(i2c_t *i2c_dev, uint16_t i2caddr)
{
//Adapted and optimized for oled_lcd.c
}
void ssd1306_display(i2c_t *i2c_dev)
{
//Adapted and optimized for oled_lcd.c
}

@ -146,33 +146,11 @@ All text above, and the splash screen must be included in any redistribution
#define SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL 0x29
#define SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL 0x2A
//switchvcc should be SSD1306_SWITCHCAPVCC
void ssd1306_begin(i2c_t *i2c_dev, uint16_t i2caddr);
void ssd1306_i2c_command(i2c_t *i2c_dev,uint16_t c);
void ssd1306_invertDisplay(i2c_t *i2c_dev, uint16_t i);
void ssd1306_display(i2c_t *i2c_dev);
void ssd1306_startscrollright(i2c_t *i2c_dev, uint16_t start, uint16_t stop);
void ssd1306_startscrollleft(i2c_t *i2c_dev,uint16_t start, uint16_t stop);
void ssd1306_clearDisplay();
void ssd1306_startscrolldiagright(i2c_t *i2c_dev, uint16_t start, uint16_t stop);
void ssd1306_startscrolldiagleft(i2c_t *i2c_dev, uint16_t start, uint16_t stop);
void ssd1306_stopscroll(i2c_t *i2c_dev);
void ssd1306_drawPixel(int16_t x, int16_t y, uint16_t color);
void ssd1306_drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
void ssd1306_drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
void ssd1306_fillRect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t fillcolor);
void ssd1306_setTextSize(int16_t s);
void ssd1306_drawString(int8_t *str);
void ssd1306_drawChar(int16_t x, int16_t y, uint8_t c, int16_t color, int16_t size);
void ssd1306_i2c_send_command(i2c_t *i2c_dev,uint8_t c);
void ssd1306_i2c_set_display_off(i2c_t *i2c_dev);
void ssd1306_i2c_set_display_on(i2c_t *i2c_dev);
void ssd1306_i2c_set_display_clkDiv_oscFreq(i2c_t *i2c_dev, uint8_t clockDivider, uint8_t oscillatorFreq);

@ -61,7 +61,7 @@ function(projectAddItem alias _currentItem)
set(${_currentItem} sub::${alias} PARENT_SCOPE)
endif()
else()
message(FATAL_ERROR "Source directory ${DIR} : NOT FOUND")
message(FATAL_ERROR "Source directory <<${DIR}>> : NOT FOUND")
endif()
endforeach()
endfunction()
@ -89,7 +89,7 @@ function(addPeripheral alias _currentPripheral)
else ()
message("${BoldRed}")
message(FATAL_ERROR "\nThe Included ${alias} peripheral was NOT found ### COMPILATION ABORTED ###\n")
message(FATAL_ERROR "\nThe Included <<${alias}>> peripheral was NOT found ### COMPILATION ABORTED ###\n")
message("${ColourReset}")
endif()
endfunction()
@ -112,17 +112,17 @@ function(addDriver alias _currentDriver)
set(${_currentDriver} sub::${alias} PARENT_SCOPE)
else ()
message("${BoldRed}")
message(FATAL_ERROR "\nThe Included ${alias} Driver's Header file was NOT found ### COMPILATION ABORTED ###\n")
message(FATAL_ERROR "\nThe Included <<${alias}>> Driver's Header file was NOT found ### COMPILATION ABORTED ###\n")
message("${ColourReset}")
endif()
else ()
message("${BoldRed}")
message(FATAL_ERROR "\nThe Included ${alias} Driver's Source file was NOT found ### COMPILATION ABORTED ###\n")
message(FATAL_ERROR "\nThe Included <<${alias}>> Driver's Source file was NOT found ### COMPILATION ABORTED ###\n")
message("${ColourReset}")
endif()
else ()
message("${BoldRed}")
message(FATAL_ERROR "\nThe Included ${alias} Driver was NOT found ### COMPILATION ABORTED ###\n")
message(FATAL_ERROR "\nThe Included <<${alias}>> Driver was NOT found ### COMPILATION ABORTED ###\n")
message("${ColourReset}")
endif()
endfunction()
@ -138,17 +138,17 @@ function(addDriverHeader alias _currentDriverHeader)
else ()
message("${BoldRed}")
message(FATAL_ERROR "\nThe Included ${alias} Driver's Header file was NOT found ### COMPILATION ABORTED ###\n")
message(FATAL_ERROR "\nThe Included <<${alias}>> Driver's Header file was NOT found ### COMPILATION ABORTED ###\n")
message("${ColourReset}")
endif()
else ()
message("${BoldRed}")
message(FATAL_ERROR "\nThe Included ${alias} Driver's Source file was NOT found ### COMPILATION ABORTED ###\n")
message(FATAL_ERROR "\nThe Included <<${alias}>> Driver's Source file was NOT found ### COMPILATION ABORTED ###\n")
message("${ColourReset}")
endif()
else ()
message("${BoldRed}")
message(FATAL_ERROR "\nThe Included ${alias} Driver was NOT found ### COMPILATION ABORTED ###\n")
message(FATAL_ERROR "\nThe Included <<${alias}>> Driver was NOT found ### COMPILATION ABORTED ###\n")
message("${ColourReset}")
endif()
endfunction()

@ -1,183 +0,0 @@
#include "i2c.h"
//uint32_t i2cCR1;
//uint32_t i2cCR2;
//uint32_t i2cISR;
void i2cInit( i2c_t *i2cHardware,
i2cCh_t channelNo,
i2cMode_t mode,
uint16_t mainAddress,
uint16_t secondAddress,
i2cAddressCount_t addressCount,
i2cAddressSize_t addressSize,
i2cSpeed_t speed,
i2cOpperationMode_t opperationMode,
i2cClockStretching_t stretching,
i2cWakeUpTypes_t wakeOn)
{
i2cHardware->channelNo = channelNo;
i2cHardware->mode = mode;
i2cHardware->mainAddress = mainAddress;
i2cHardware->secondAddress = secondAddress;
i2cHardware->addressCount = addressCount;
i2cHardware->addressSize = addressSize;
i2cHardware->speed = speed;
i2cHardware->opperationMode = opperationMode;
i2cHardware->stretching = stretching;
i2cHardware->wakeOn = wakeOn;
i2cHardware->hardwareState = i2cHwIdle;
i2cHardware->periferalState = i2cPerifNotInitialized;
i2cEnableHardware(i2cHardware);
i2cDisablePeriferal(i2cHardware);
i2cConfigureFilters(i2cHardware);
i2cSetClockStretch(i2cHardware, stretching);
i2cSetSpeed(i2cHardware, speed);
i2cSetMode(i2cHardware, opperationMode);
i2cSetAddressLenght(i2cHardware, addressSize);
i2cSetAddress(i2cHardware, mainAddress, secondAddress);
i2cEnablePeriferal(i2cHardware);
i2cHardware->periferalState = i2cPerifNotInitialized;
}
void i2cDeInit(i2c_t *i2cHardware)
{
}
void i2cRead(i2c_t *i2cHardware, uint16_t *slaveAddress, uint8_t *registerAddress, uint8_t *data, uint8_t *dataLenght)
{
switch(i2cHardware->mode)
{
case i2cModeMaster:
i2cMasterRecieve(i2cHardware, slaveAddress, registerAddress, data);
break;
case i2cModeSlave:
break;
case i2cModeMultyMaster:
break;
}
}
// this function still doesn't implment 10 bit oopeartion
void i2cMasterRecieve(i2c_t *i2cHardware, uint16_t *slaveAddress, uint8_t *registerAddress, uint8_t *data)
{
switch(i2cHardware->opperationMode)
{
case i2cOpperationPolling :
i2cMasterRecievePolling(i2cHardware, slaveAddress, registerAddress, data);
break;
case i2cOpperationInt:
break;
case i2cOpperationDma:
break;
}
}
void i2cWrite(i2c_t *i2cHardware, uint16_t *slaveAddress, uint8_t *registerAddress, uint8_t *data, uint8_t *dataLenght)
{
switch(i2cHardware->mode)
{
case i2cModeMaster:
i2cMasterSend(i2cHardware, slaveAddress, registerAddress, data);
break;
case i2cModeSlave:
break;
case i2cModeMultyMaster:
break;
}
}
void i2cMasterSend(i2c_t *i2cHardware, uint16_t *slaveAddress, uint8_t *registerAddress, uint8_t *data)
{
switch(i2cHardware->opperationMode)
{
case i2cOpperationPolling :
i2cMasterSendPolling(i2cHardware, slaveAddress, registerAddress, data);
break;
case i2cOpperationInt:
break;
case i2cOpperationDma:
break;
}
}
void i2cMasterSendPolling(i2c_t *i2cHardware, uint16_t *slaveAddress, uint8_t *registerAddress, uint8_t *data)
{
while(i2cHardware->periferalState != i2cPerifReady)
{
i2cIsPeriferalReady(i2cHardware);
}
i2cHardware->periferalState = i2cPerifTransmitting;
i2cInitiateWriteCommand(i2cHardware);
i2cSetTransferCounter(i2cHardware,2);
i2cSendSlaveAddress(i2cHardware, slaveAddress);
i2cSendRegisterAddress(i2cHardware,registerAddress);
i2cSendData(i2cHardware,data);
while(i2cHardware->periferalState != i2cPerifTransferComplete)
{
i2cIsTransferComplete(i2cHardware);
}
i2cGenerateStop(i2cHardware);
i2cHardware->periferalState = i2cPerifReady;
i2cHardware->hardwareState = i2cHwIdle;
}
void i2cMasterRecievePolling(i2c_t *i2cHardware, uint16_t *slaveAddress, uint8_t *registerAddress, uint8_t *data)
{
while(i2cHardware->periferalState != i2cPerifReady)
{
i2cIsPeriferalReady(i2cHardware);
}
i2cHardware->periferalState = i2cPerifTransmitting;
i2cSetTransferCounter(i2cHardware,1);
i2cInitiateWriteCommand(i2cHardware);
i2cSendSlaveAddress(i2cHardware, slaveAddress);
i2cSendRegisterAddress(i2cHardware,registerAddress);
while(i2cHardware->periferalState != i2cPerifTransferComplete)
{
i2cIsTransferComplete(i2cHardware);
}
i2cInitiateReadCommand(i2cHardware);
i2cSendSlaveAddress(i2cHardware, slaveAddress);
i2cHardware->periferalState = i2cPerifRecieving;
while(i2cHardware->hardwareState != i2cHwInputBufferFull)
{
i2cIsInputBufferEmpty(i2cHardware);
}
i2cGenerateNack(i2cHardware);
i2cGenerateStop(i2cHardware);
i2cReadInputRegister(i2cHardware, data);
i2cHardware->periferalState = i2cPerifReady;
i2cHardware->hardwareState = i2cHwIdle;
}

@ -1,552 +0,0 @@
/**
**************************************************************************************************
* @file i2c.h
* @author Kerem Yollu & Edwin Koch
* @date 18.07.2022
* @version 1.01
**************************************************************************************************
* @brief I2C communitation based on the Standart I2C Protocol V7 Defined by NXP/Philips :
* following third Party Protocols based on I2C Bus are not going to be implemented : C-BUS SMBUS PMBUS IPMI DDC ATCA
* This will also not have a I3C support for the forseable futrue.
*
* **Detailed Description :**
*
* I2C communitation based on the Standart I2C Protocol V7 Defined by NXP/Philips :
* following third Party Protocols based on I2C Bus are not going to be implemented : C-BUS SMBUS PMBUS IPMI DDC ATCA
* This will also not have a I3C support for the forseable futrue.
*
* @todo
* - 26.07.2021 : Implement the DMA
* - 26.07.2021 : Implement the Interrupt
* - 26.07.2021 : Implement the Sleep/WakeUp
* - 26.07.2021 : Implement the Slave opperation
**************************************************************************************************
*/
#ifndef _I2C_H_
#define _I2C_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "hardwareDescription.h"
#include "pin.h"
/*! Enum of possible I2C opperation modes */
typedef enum{
i2cModeMaster, /*!< Master mode : In Master mode, the I2C interface initiates
a data transfer and generates the clock signal. **DEFAULT** */
i2cModeMultyMaster, /*!< Multimaster Mode : In case if more than one master are present
in one I2C bus. In such case each device needs to be able to
cooperate knowing that another device could talking
therefore the bus is busy (Arbirtation).
For More information : https://www.i2c-bus.org/multimaster/ */
i2cModeSlave /*!< Slave mode : A slave device has to always be ready to detect and
process a start condition and to recognize its address */
}i2cMode_t;
/*! Enum of possible I2C speeds */
typedef enum{
i2cSpeedStandart, /*!< SM 100 kbits/s Standart i2c Speed **DEFAULT** */
i2cSpeedFast, /*!< FM 400 kbits/s */
i2cSpeedFastPlus, /*!< FM+ 1 Mbits/s */
i2cSpeedHightSpeed, /*!< HS 3.4 Mbits/s */
i2cSpeedUltraFast /*!< UFM 5 Mbits/s */
}i2cSpeed_t;
/*! Enum of possible I2C Adress sizes */
typedef enum{
i2cAddressSizeSevenBits, /*!< 7 Bits address size **DEFAULT** */
i2cAddressSizeTenBits /*!< 10 Bits address size */
}i2cAddressSize_t;
/*! Enum of possible I2C Address count */
typedef enum{
i2cAddressCountSingle, /*!< Only one address for communication **DEFAULT** */
i2cAddressCountDual /*!< Dual addresses for one device respondng to two addresses */
}i2cAddressCount_t;
/*! Enum for clock strechning activation. Can only be implmented as Slave
* for more information : https://www.i2c-bus.org/clock-stretching/ */
typedef enum{
i2cClockStretchingDisable, /*!< We assume that the master and slave have compatible
Clock frequencies **DEFAULT** */
i2cClockStretchingEnable /*!< In situations where an I2C slave is not able to co-operate
with the clock speed given by the master and needs to slow down.
This is done by a mechanism referred to as clock stretching. */
}i2cClockStretching_t;
/*! Enum for diffenrent wake up methodes wehnin sleep mode */
typedef enum{
i2cWakeUpDisabled, /*!< No wake up is possible this is the default mode also means that
the sleep function is not implmentes **DEFAULT** */
i2cWakeUpOnAddressMatch /*!< Wakes up on address match, this can be harware dependent */
}i2cWakeUpTypes_t;
/*! Enum operation mode of the i2c channel */
typedef enum{
i2cOpperationPolling, /*!< Polling mode Blocking, i2c communication states are constantly
checked on polling mode so it can be stoped
when interrupts occures **DEFAULT** */
i2cOpperationInt, /*!< Interrut Mode Non-blocking, i2c communications state changes
generates an interrupt and can be handeled this way */
i2cOpperationDma /*!< DMA Mode Non-blocking, I2C communication satets are managed
via Inteerupts and with Direct Memory Access */
}i2cOpperationMode_t;
/*! typedef for the i2c states*/
typedef enum
{
i2cHwIdle, /*!< Hardware is in Idle Mode **DEFAULT** */
i2cHwStartGenerated, /*!< Generated the star condition */
i2cHwOutputBufferFull, /*!< The output buffer of the I2C Periferal is Full */
i2cHwOutputBufferEmpty, /*!< The output buffer of the I2C Periferal is Empty */
i2cHwInputBufferFull, /*!< The input buffer of the I2C Periferal Is Full */
i2cHwInputBufferEmpty, /*!< The input buffer of the I2C Periferal Is Empty */
i2cHwSentRead, /*!< Sent read request */
i2cHwSentWrite, /*!< Sent write request */
i2cHwGotAck, /*!< Recieved ACK */
i2cHwGotNack, /*!< Recieved NACK */
i2cHwSentAck, /*!< Sent ACK */
i2cHwSentNack, /*!< Sent NACK */
i2cHwStopGenerated, /*!< Generated the star condition */
i2cHwError /*!< Error */
} i2cHardwareState_t;
typedef enum
{
i2cPerifNotInitialized, /*!< Default Peripheral is not yet Initialized **DEFAULT** */
i2cPerifInitialized, /*!< I2C CHannle is initilized but not neceserly ready */
i2cPerifSlaveAddressSent, /*!< The Salve Address Was Sent to the bus */
i2cPerifTransferComplete, /*!< A full communication process is complete (wire or Read) */
i2cPerifTransferOngoign, /*!< A full communication process is in progress (wire or Read) */
i2cPerifReady, /*!< Peripheral Initialized and ready for use */
i2cPerifSlaveNotFound, /*!< Desired Slave was not able to be found */
i2cPerifTransmitting, /*!< Data Transmission process is ongoing */
i2cPerifRecieving, /*!< Data Reception process is ongoing */
i2cPerifListening, /*!< Address Listen Mode is ongoing */
i2cPerifListeningAndTransmitting, /*!< Address Listen Mode and ongoing Data Transmission */
i2cPerifListeningAndRecieveing, /*!< Address Listen Mode and ongoing Data Reception */
i2cPerifAbort, /*!< Abort user request ongoing */
i2cPerifTimeout, /*!< Timeout state */
i2cPerifError /*!< Error */
} i2cPeriferalState_t;
/*! Struture a an i2c channel with all the required propereties*/
typedef struct i2c_t
{
i2cCh_t channelNo; /*!< The harware channel to be used */
i2cMode_t mode; /*!< Master, Slave or Multymaster Modes */
uint16_t mainAddress; /*!< First and Main address of the device */
uint16_t secondAddress; /*!< Second address if dual addresse mode is configured */
i2cAddressCount_t addressCount; /*!< Single or multiple */
i2cAddressSize_t addressSize; /*!< 10 or 7 bit address size */
i2cSpeed_t speed; /*!< Bus Speed */
i2cOpperationMode_t opperationMode; /*!< Blocking or non blocking polling, Int or DMA */
i2cClockStretching_t stretching; /*!< Clock Stretching enable onyl in slave mode */
i2cWakeUpTypes_t wakeOn; /*!< Define on which type of action the i2c channel should
wake up. Only if de prefiral goes to sleep */
i2cHardwareState_t hardwareState; /*!< The current sitate of the I2C Bus */
i2cPeriferalState_t periferalState; /*!< The current sitate of the I2C Bus */
}i2c_t;
/***************************************************************************************************
I2C Configuration functions
***************************************************************************************************/
/**
* @brief Initilize the I2C Hardware
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
void i2cInit( i2c_t *i2cHardware, /*!< Pointer to I2C hardware Object */
i2cCh_t channelNo, /*!< The harware channel to be used */
i2cMode_t mode, /*!< Master, Slave or Multymaster Modes */
uint16_t mainAddress, /*!< First and Main address of the device */
uint16_t secondAddress, /*!< Second address if dual addresse mode is configured */
i2cAddressCount_t addressCount, /*!< Single or multiple */
i2cAddressSize_t addressSize, /*!< 10 or 7 bit address size */
i2cSpeed_t speed, /*!< Bus Speed */
i2cOpperationMode_t opperationMode, /*!< Blocking or non blocking polling, Int or DMA */
i2cClockStretching_t stretching, /*!< Clock Stretching enable onyl in slave mode */
i2cWakeUpTypes_t wakeOn /*!< Wake up condition */
);
/**
* @brief De-Initilize the I2C Hardware
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
void i2cDeInit(i2c_t *i2cHardware);
/**
* @brief Set the i2c channle to the gievn mode
* @param Channel is the i2c hardware channel
* @param mode The mode for i2c : Master Slave or Multymaster
*/
void i2cSetMode(i2c_t *i2cHardware, i2cMode_t mode);
/**
* @brief Set the i2c channles mode as Master Slave or Multymaster
* @param i2cHardware is the i2c hardware channel
* @param addressOne The forst address for the device
* @param addressTwo The second address for the device only if dual address mode is not defined
*/
void i2cSetAddress(i2c_t *i2cHardware, uint16_t mainAddress, uint16_t secondAddress);
/**
* @brief Set the i2c Address Lenght, 7 bit or 8 bit, Master or slave doesn't make any difference
* @param i2cHardware is the i2c hardware channel
* @param size Is the Adress isze to be used 7 Bit or 10 Bit
*/
void i2cSetAddressLenght(i2c_t *i2cHardware, i2cAddressSize_t size);
/**
* @brief Stets the Communication speed
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param speed the different awailable speeds
*/
void i2cSetSpeed(i2c_t *i2cHardware, i2cSpeed_t speed);
/**
* @brief Initiates the opperation mode for the selected i2c Channel
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param opperation define if the i2c channel will opperate on pollin, Interrupt, or DMA modes
*/
void i2cSetOpperation(i2c_t *i2cHardware, i2cOpperationMode_t opperation);
/**
* @brief Ebales or disables clock stretching functionalities
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param The value to be written in the register. This will heavily depend on the hardware
*/
void i2cSetClockStretch(i2c_t *i2cHardware, i2cClockStretching_t stretching);
/**
* @brief Set the wakeup mode
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param wake the desider wakeup mode for now i have found only one mode.
*/
void i2cSetWakeup(i2c_t *i2cHardware, i2cWakeUpTypes_t wake);
/**
* @brief Configures Hardware implmente filters if there are any.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
void i2cConfigureFilters(i2c_t *i2cHardware);
/**
* @brief Set the timeout to close the i2c wait time if a communication fails.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param timeout the desider timeout duration in ticks.
*/
void i2cSetTimeout(i2c_t *i2cHardware, uint8_t timeout);
/**
* @brief Resets the i2c Periferal to it's inital state.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
void i2cPeriferalReset(i2c_t *i2cHardware);
/**
* @brief Resets the i2c Harware and register to it's factory deflauts.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
void i2cHardwareReset(i2c_t *i2cHardware);
/**
* @brief Enables I2C Hardware BUS & Clock & Pins
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
void i2cEnableHardware(i2c_t *i2cHardware);
/**
* @brief Enables I2C Periferal core.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
void i2cEnablePeriferal(i2c_t *i2cHardware);
/**
* @brief Disables I2C Periferal core.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
void i2cDisablePeriferal(i2c_t *i2cHardware);
/**************************************************************************************************
I2C Communication functions independen of opperating mode
***************************************************************************************************/
/**
* @brief Writes the given amount of data to the selected device. This function will
* automaticaly choose between i2cMasterSend(); or i2cSlaveSend();
* Depending if the I2C channel was initiated as slave or master.
* this function will adapt himself to the selected oppeartion mode (Polling / Int / DMA)
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param slaveAddress is the address of the device to which the read command will be sent
* @param registerAddress is the regiter to be red from the device
* @param data is the data to be written
* @param dataLenght is the total quantity of 8 bit data to be written.
*/
void i2cWrite(i2c_t *i2cHardware, uint16_t *slaveAddress, uint8_t *registerAddress, uint8_t *data, uint8_t *dataLenght);
/**
* @brief Reads the given amount of data to the selected device. This function will
* automaticaly choose between i2cMasterRecieve(); or i2cSlaveRecieve();
* Depending if the I2C channel was initiated as slave or master.
* this function will adapt himself to the selected oppeartion mode (Polling / Int / DMA)
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param slaveAddress is the address of the device to which the read command will be sent
* @param registerAddress is the regiter to be red from the device
* @param data is the data which has been red
* @paran dataLenght is the total quantity of 8 bit data to be red
*/
void i2cRead(i2c_t *i2cHardware, uint16_t *slaveAddress, uint8_t *registerAddress, uint8_t *data, uint8_t *dataLenght);
/**
* @brief Recieve a Single Byte as master from from the given devices register.
* this function will adapt himself to the selected oppeartion mode (Polling / Int / DMA)
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param slaveAddress is the address of the device to which the read command will be sent
* @param registerAddress is the regiter to be red from the device
* @param data is the data whic has been red
*/
void i2cMasterRecieve(i2c_t *i2cHardware, uint16_t *slaveAddress, uint8_t *registerAddress, uint8_t *data);
/**
* @brief Sends a Single Byte as master to the given devices register.
* this function will adapt himself to the selected oppeartion mode (Polling / Int / DMA)
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param slaveAddress is the address of the device to which the send command will be sent
* @param registerAddress is the regiter to be written to the device
* @param data is the data to be sent
*/
void i2cMasterSend(i2c_t *i2cHardware, uint16_t *slaveAddress, uint8_t *registerAddress, uint8_t *data);
/**
* @brief Recieve a Single Byte as slave from given devices register.
* this function will adapt himself to the selected oppeartion mode (Polling / Int / DMA)
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param slaveAddress is the address of the device to which the read command will be sent
* @param registerAddress is the regiter to be red from the device
* @param data is the data whic has been red
*/
void i2cSlaveRecieve(i2c_t *i2cHardware, uint16_t *slaveAddress, uint8_t *registerAddress, uint8_t *data);
/**
* @brief Recieve a Single Byte as slave from the given devices register.
* this function will adapt himself to the selected oppeartion mode (Polling / Int / DMA)
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param slaveAddress is the address of the device to which the read command will be sent
* @param registerAddress is the regiter to be red from the device
* @param data is the data whic has been red
*/
void i2cSlaveSend(i2c_t *i2cHardware, uint16_t *slaveAddress, uint8_t *registerAddress, uint8_t *data);
/**************************************************************************************************
I2C Hardware functions
***************************************************************************************************/
/**
* @brief Checks if the device is ready for any type of communication
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
void i2cIsPeriferalReady(i2c_t *i2cHardware);
/**
* @brief Generates a Start condition.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
void i2cGenerateStart(i2c_t *i2cHardware);
/**
* @brief Generates a Start condition.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
void i2cGenerateStop(i2c_t *i2cHardware);
/**
* @brief Generates a NACK condition.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
void i2cGenerateNack(i2c_t *i2cHardware);
/**
* @brief Generates a ACK condition.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
void i2cGenerateAck(i2c_t *i2cHardware);
/**
* @brief Initiates the communication protocl by sending the slave address on the bus and waits
* for an ACK (aknowledge)
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param slaveAddress The address of the slave to be communicated
*/
void i2cSendSlaveAddress(i2c_t *i2cHardware, uint16_t *slaveAddress);
/**
* @brief Sende the register adrres with which we want to communicate.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param registerAddress The register address of the slave device that we are communication with
*/
void i2cSendRegisterAddress(i2c_t *i2cHardware, uint8_t *registerAddress);
/**
* @brief Send the register that we want to read or write.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param registerAddress the register that need to be accessed
*/
void i2cSendData(i2c_t *i2cHardware, uint8_t *registerAddress);
/**
* @brief Initiates a Write command with the previously set slave address.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
void i2cInitiateWriteCommand(i2c_t *i2cHardware);
/**
* @brief Initiates a read command with the previously set slave address.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
void i2cInitiateReadCommand(i2c_t *i2cHardware);
/**
* @brief Is the output buffer empty. This allso meas that the data that was in the ouput buffer
* is sent to the i2c BUS.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
void i2cIsOutputBufferEmpty(i2c_t *i2cHardware);
/**
* @brief Is the output buffer empty. This allso meas that the data that was in the ouput buffer
* is sent to the i2c BUS.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
void i2cIsInputBufferEmpty(i2c_t *i2cHardware);
/**
* @brief reads the I2C input buffer
* is sent to the i2c BUS.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param data pointer to the data that need to be read and returned
*/
void i2cReadInputRegister(i2c_t *i2cHardware, uint8_t *data);
/**
* @brief writes to the I2C output buffer
* is sent to the i2c BUS.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param data pointer to the data that need to be read and returned
*/
void i2cSetOutputRegister(i2c_t *i2cHardware, uint8_t *data);
/**
* @brief Checks is transfer is complete
* is sent to the i2c BUS.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param data pointer to the data that need to be read and returned
*/
void i2cIsTransferComplete(i2c_t *i2cHardware);
/**
* @brief Defines the amount of transfers to be made. Address exchange and start conditon does not count
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param count amount o data to be transfered.
*/
void i2cSetTransferCounter(i2c_t *i2cHardware, uint8_t count);
/**************************************************************************************************
I2C Communication functions Polling / Blocking Mode
***************************************************************************************************/
/**
* @brief Recieve a Single Byte in polling mode as master from from the given devices register.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param slaveAddress is the address of the device to which the read command will be sent
* @param registerAddress is the regiter to be red from the device
* @param data is the data whic has been red
*/
void i2cMasterRecievePolling(i2c_t *i2cHardware, uint16_t *slaveAddress, uint8_t *registerAddress, uint8_t *data);
/**
* @brief Sends a Single Byte in polling mode as master to the given devices register.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param slaveAddress is the address of the device to which the send command will be sent
* @param registerAddress is the regiter to be written to the device
* @param data is the data to be sent
*/
void i2cMasterSendPolling(i2c_t *i2cHardware, uint16_t *slaveAddress, uint8_t *registerAddress, uint8_t *data);
/**
* @brief Recieve a Single Byte in polling mide as slave from the given devices register.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param slaveAddress is the address of the device to which the read command will be sent
* @param registerAddress is the regiter to be red from the device
* @param data is the data whic has been red
*/
void i2cSlaveRecievePolling(i2c_t *i2cHardware, uint16_t *slaveAddress, uint8_t *registerAddress, uint8_t *data);
/**
* @brief Recieve a Single Byte in polling mode as slave from the given devices register.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param slaveAddress is the address of the device to which the read command will be sent
* @param registerAddress is the regiter to be red from the device
* @param data is the data whic has been red
*/
void i2cSlaveSendPolling(i2c_t *i2cHardware, uint16_t *slaveAddress, uint8_t *registerAddress, uint8_t *data);
/**************************************************************************************************
I2C Arbitration Functions for Multymaster mode and slaves clock stretching
***************************************************************************************************/
void i2cClockSynchronise(); // I2C Standart : Clock Syncronization
void i2cAbortTransmit(); // I2c Standart : Stop Communication for multimaster mode
void i2cArbitration(); // I2C Standart : Arbitration for multimaster mode to define the right master.
void i2cSoftReset(); // I2C Standart : Software reset not supported by all hardware.
void i2cBusClear(); // I2C Standart : in case if SCL is stuck
/**************************************************************************************************
I2C Extra functions that are not esential for the main functionality
***************************************************************************************************/
/**
* @brief This function will scan every for possible addresses to discover devices on the bus.
* And write them to the Devices list given to him. This function will not discover more
* devices than what he is told.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param devices list where the discevered devices will be written
* @param deviceCount Max number of devices to be discovered.
*/
void i2cDiscoverDevices(i2c_t *i2cHardware, uint16_t *devices, uint8_t deviceCount);
/**
* @brief This function will try to communicate with a device with every speed
* allowed by his hardware to find out the maximum communication sppeed possible.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param slaveAddress is the address of the device to which the read command will be sent
*/
i2cSpeed_t i2cTestDeviceSpeed(i2c_t *i2cHardware, uint16_t *slaveAddress);
/**
* @brief This function will read the device info register (if awailable) as follows :
* I2c Standart : 3 Bytes (24 bits) | 12 Bits : Manufacturer info | 9 Bits: Part Identification | 3 Bits DIE Rev.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param slaveAddress is the address of the device to be red
*/
uint32_t i2cReadDeviceInfo(i2c_t *i2cHardware, uint16_t *slaveAddress);
/**
* @brief The selected i2c channel is put on sleep.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
void i2cSleep(i2c_t *i2cHardware);
/**
* @brief Error handling.
* @param error The error no generated.
*/
void i2cThrowError(int16_t error); // Defined by me : Private error function for error handling
#ifdef __cplusplus
}
#endif
#endif // _I2C_H_

@ -1,130 +0,0 @@
#include "i2c.h"
#include "usart.h"
void i2cInit( i2c_t *i2cHardware,
i2cCh_t channelNo,
i2cMode_t mode,
uint16_t mainAddress,
uint16_t secondAddress,
i2cAddressCount_t addressCount,
i2cAddressSize_t addressSize,
i2cSpeed_t speed,
i2cOpperationMode_t opperationMode,
i2cClockStretching_t stretching,
i2cWakeUpTypes_t wakeOn)
{
i2cHardware->channelNo = channelNo;
i2cHardware->mode = mode;
i2cHardware->mainAddress = mainAddress;
i2cHardware->secondAddress = secondAddress;
i2cHardware->addressCount = addressCount;
i2cHardware->addressSize = addressSize;
i2cHardware->speed = speed;
i2cHardware->opperationMode = opperationMode;
i2cHardware->stretching = stretching;
i2cHardware->wakeOn = wakeOn;
i2cHardware->hardwareState = i2cHwIdle;
i2cHardware->periferalState = i2cPerifNotInitialized;
i2cEnableHardware(i2cHardware);
i2cDisablePeriferal(i2cHardware);
i2cConfigureFilters(i2cHardware);
i2cSetClockStretch(i2cHardware, stretching);
i2cSetSpeed(i2cHardware, speed);
i2cSetMode(i2cHardware, opperationMode);
i2cSetAddressLenght(i2cHardware, addressSize);
i2cSetAddress(i2cHardware, mainAddress, secondAddress);
i2cEnablePeriferal(i2cHardware);
while(i2cHardware->periferalState != i2cPerifReady)
{
i2cIsPeriferalReady(i2cHardware);
}
i2cHardware->periferalState = i2cPerifInitialized;
}
void i2cDeInit(i2c_t *i2cHardware)
{
}
void i2cRead(i2c_t *i2cHardware, uint16_t *slaveAddress, uint8_t *registerAddress, uint8_t *data, uint8_t *dataLenght)
{
//
// Start
// Send Address
// Wait For ACK
//
uint8_t nbytes = 0;
i2cHardware->periferalState = i2cPerifTransmitting;
i2cSetTransferCounter(i2cHardware,1);
i2cSendSlaveAddressWrite(i2cHardware, slaveAddress);
i2cSendRegisterAddress(i2cHardware,registerAddress);
while(i2cHardware->periferalState != i2cPerifTransferComplete)
{
i2cIsTransferComplete(i2cHardware);
}
i2cHardware->periferalState = i2cPerifRecieving;
i2cSendSlaveAddressRead(i2cHardware, slaveAddress);
while(i2cHardware->periferalState != i2cPerifTransferComplete)
{
i2cIsTransferComplete(i2cHardware);
}
i2cGenerateNack(i2cHardware);
i2cGenerateStop(i2cHardware);
i2cReadInputRegister(i2cHardware, data);
print_Usart(usart2, "\n\rI2C Read completed\n\r");
while(i2cHardware->periferalState != i2cPerifReady)
{
i2cIsPeriferalReady(i2cHardware);
}
i2cHardware->periferalState = i2cPerifReady;
i2cHardware->hardwareState = i2cHwIdle;
}
void i2cWrite(i2c_t *i2cHardware, uint16_t *slaveAddress, uint8_t *registerAddress, uint8_t *data, uint8_t *dataLenght)
{
i2cSetTransferCounter(i2cHardware,2);
i2cSendSlaveAddressWrite(i2cHardware, slaveAddress);
i2cSendRegisterAddress(i2cHardware,registerAddress);
while((i2cHardware->hardwareState =! i2cHwOutputBufferEmpty))
{
i2cIsOutputBufferEmpty(i2cHardware);
}
i2cSendData(i2cHardware,data);
i2cGenerateStop(i2cHardware);
print_Usart(usart2, "\n\rI2C Transfer completed\n\r");
}
void i2cThrowError(i2c_t *i2cHardware, int16_t error)
{
print_Usart(usart2, "\n\r");
print_Usart(usart2, "\n\r");
print_Usart(usart2, "I2C Error Detected : ");
if (i2cHardware->periferalState == i2cPerifTransmitting)
print_Usart(usart2, "i2cPerifTransmitting");
if (i2cHardware->periferalState == i2cPerifRecieving)
print_Usart(usart2, "i2cPerifRecieving");
print_Usart(usart2, "\n\r");
print_Usart(usart2, "I2C Error No: ");
usartSendChar(usart2, error + 0x30);
print_Usart(usart2, "\n\r");
print_Usart(usart2, "\n\r");
}

@ -1,565 +0,0 @@
/**
**************************************************************************************************
* @file i2c.h
* @author Kerem Yollu & Edwin Koch
* @date 18.07.2022
* @version 1.01
**************************************************************************************************
* @brief I2C communitation based on the Standart I2C Protocol V7 Defined by NXP/Philips :
* following third Party Protocols based on I2C Bus are not going to be implemented : C-BUS SMBUS PMBUS IPMI DDC ATCA
* This will also not have a I3C support for the forseable futrue.
*
* **Detailed Description :**
*
* I2C communitation based on the Standart I2C Protocol V7 Defined by NXP/Philips :
* following third Party Protocols based on I2C Bus are not going to be implemented : C-BUS SMBUS PMBUS IPMI DDC ATCA
* This will also not have a I3C support for the forseable futrue.
*
* @todo
* - 26.07.2021 : Implement the DMA
* - 26.07.2021 : Implement the Interrupt
* - 26.07.2021 : Implement the Sleep/WakeUp
* - 26.07.2021 : Implement the Slave opperation
**************************************************************************************************
*/
#ifndef _I2C_H_
#define _I2C_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "hardwareDescription.h"
#include "pin.h"
/*! Enum of possible I2C opperation modes */
typedef enum{
i2cModeMaster, /*!< Master mode : In Master mode, the I2C interface initiates
a data transfer and generates the clock signal. **DEFAULT** */
i2cModeMultyMaster, /*!< Multimaster Mode : In case if more than one master are present
in one I2C bus. In such case each device needs to be able to
cooperate knowing that another device could talking
therefore the bus is busy (Arbirtation).
For More information : https://www.i2c-bus.org/multimaster/ */
i2cModeSlave /*!< Slave mode : A slave device has to always be ready to detect and
process a start condition and to recognize its address */
}i2cMode_t;
/*! Enum of possible I2C speeds */
typedef enum{
i2cSpeedStandart, /*!< SM 100 kbits/s Standart i2c Speed **DEFAULT** */
i2cSpeedFast, /*!< FM 400 kbits/s */
i2cSpeedFastPlus, /*!< FM+ 1 Mbits/s */
i2cSpeedHightSpeed, /*!< HS 3.4 Mbits/s */
i2cSpeedUltraFast /*!< UFM 5 Mbits/s */
}i2cSpeed_t;
/*! Enum of possible I2C Adress sizes */
typedef enum{
i2cAddressSizeSevenBits, /*!< 7 Bits address size **DEFAULT** */
i2cAddressSizeTenBits /*!< 10 Bits address size */
}i2cAddressSize_t;
/*! Enum of possible I2C Address count */
typedef enum{
i2cAddressCountSingle, /*!< Only one address for communication **DEFAULT** */
i2cAddressCountDual /*!< Dual addresses for one device respondng to two addresses */
}i2cAddressCount_t;
/*! Enum for clock strechning activation. Can only be implmented as Slave
* for more information : https://www.i2c-bus.org/clock-stretching/ */
typedef enum{
i2cClockStretchingDisable, /*!< We assume that the master and slave have compatible
Clock frequencies **DEFAULT** */
i2cClockStretchingEnable /*!< In situations where an I2C slave is not able to co-operate
with the clock speed given by the master and needs to slow down.
This is done by a mechanism referred to as clock stretching. */
}i2cClockStretching_t;
/*! Enum for diffenrent wake up methodes wehnin sleep mode */
typedef enum{
i2cWakeUpDisabled, /*!< No wake up is possible this is the default mode also means that
the sleep function is not implmentes **DEFAULT** */
i2cWakeUpOnAddressMatch /*!< Wakes up on address match, this can be harware dependent */
}i2cWakeUpTypes_t;
/*! Enum operation mode of the i2c channel */
typedef enum{
i2cOpperationPolling, /*!< Polling mode Blocking, i2c communication states are constantly
checked on polling mode so it can be stoped
when interrupts occures **DEFAULT** */
i2cOpperationInt, /*!< Interrut Mode Non-blocking, i2c communications state changes
generates an interrupt and can be handeled this way */
i2cOpperationDma /*!< DMA Mode Non-blocking, I2C communication satets are managed
via Inteerupts and with Direct Memory Access */
}i2cOpperationMode_t;
/*! typedef for the i2c states*/
typedef enum
{
i2cHwIdle, /*!< Hardware is in Idle Mode **DEFAULT** */
i2cHwStartGenerated, /*!< Generated the star condition */
i2cHwOutputBufferFull, /*!< The output buffer of the I2C Periferal is Full */
i2cHwOutputBufferEmpty, /*!< The output buffer of the I2C Periferal is Empty */
i2cHwInputBufferFull, /*!< The input buffer of the I2C Periferal Is Full */
i2cHwInputBufferEmpty, /*!< The input buffer of the I2C Periferal Is Empty */
i2cHwSentRead, /*!< Sent read request */
i2cHwSentWrite, /*!< Sent write request */
i2cHwGotAck, /*!< Recieved ACK */
i2cHwGotNack, /*!< Recieved NACK */
i2cHwSentAck, /*!< Sent ACK */
i2cHwSentNack, /*!< Sent NACK */
i2cHwStopGenerated, /*!< Generated the star condition */
i2cHwError /*!< Error */
} i2cHardwareState_t;
typedef enum
{
i2cPerifNotInitialized, /*!< Default Peripheral is not yet Initialized **DEFAULT** */
i2cPerifInitialized, /*!< I2C CHannle is initilized but not neceserly ready */
i2cPerifSlaveAddressSent, /*!< The Salve Address Was Sent to the bus */
i2cPerifTransferComplete, /*!< A full communication process is complete (wire or Read) */
i2cPerifTransferOngoign, /*!< A full communication process is in progress (wire or Read) */
i2cPerifReady, /*!< Peripheral Initialized and ready for use */
i2cPerifSlaveNotFound, /*!< Desired Slave was not able to be found */
i2cPerifTransmitting, /*!< Data Transmission process is ongoing */
i2cPerifRecieving, /*!< Data Reception process is ongoing */
i2cPerifListening, /*!< Address Listen Mode is ongoing */
i2cPerifListeningAndTransmitting, /*!< Address Listen Mode and ongoing Data Transmission */
i2cPerifListeningAndRecieveing, /*!< Address Listen Mode and ongoing Data Reception */
i2cPerifAbort, /*!< Abort user request ongoing */
i2cPerifTimeout, /*!< Timeout state */
i2cPerifError /*!< Error */
} i2cPeriferalState_t;
/*! Struture a an i2c channel with all the required propereties*/
typedef struct i2c_t
{
i2cCh_t channelNo; /*!< The harware channel to be used */
i2cMode_t mode; /*!< Master, Slave or Multymaster Modes */
uint16_t mainAddress; /*!< First and Main address of the device */
uint16_t secondAddress; /*!< Second address if dual addresse mode is configured */
i2cAddressCount_t addressCount; /*!< Single or multiple */
i2cAddressSize_t addressSize; /*!< 10 or 7 bit address size */
i2cSpeed_t speed; /*!< Bus Speed */
i2cOpperationMode_t opperationMode; /*!< Blocking or non blocking polling, Int or DMA */
i2cClockStretching_t stretching; /*!< Clock Stretching enable onyl in slave mode */
i2cWakeUpTypes_t wakeOn; /*!< Define on which type of action the i2c channel should
wake up. Only if de prefiral goes to sleep */
i2cHardwareState_t hardwareState; /*!< The current sitate of the I2C Bus */
i2cPeriferalState_t periferalState; /*!< The current sitate of the I2C Bus */
}i2c_t;
/***************************************************************************************************
I2C Configuration functions
***************************************************************************************************/
/**
* @brief Initilize the I2C Hardware
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
void i2cInit( i2c_t *i2cHardware, /*!< Pointer to I2C hardware Object */
i2cCh_t channelNo, /*!< The harware channel to be used */
i2cMode_t mode, /*!< Master, Slave or Multymaster Modes */
uint16_t mainAddress, /*!< First and Main address of the device */
uint16_t secondAddress, /*!< Second address if dual addresse mode is configured */
i2cAddressCount_t addressCount, /*!< Single or multiple */
i2cAddressSize_t addressSize, /*!< 10 or 7 bit address size */
i2cSpeed_t speed, /*!< Bus Speed */
i2cOpperationMode_t opperationMode, /*!< Blocking or non blocking polling, Int or DMA */
i2cClockStretching_t stretching, /*!< Clock Stretching enable onyl in slave mode */
i2cWakeUpTypes_t wakeOn /*!< Wake up condition */
);
/**
* @brief De-Initilize the I2C Hardware
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
void i2cDeInit(i2c_t *i2cHardware);
/**
* @brief Set the i2c channle to the gievn mode
* @param Channel is the i2c hardware channel
* @param mode The mode for i2c : Master Slave or Multymaster
*/
void i2cSetMode(i2c_t *i2cHardware, i2cMode_t mode);
/**
* @brief Set the i2c channles mode as Master Slave or Multymaster
* @param i2cHardware is the i2c hardware channel
* @param addressOne The forst address for the device
* @param addressTwo The second address for the device only if dual address mode is not defined
*/
void i2cSetAddress(i2c_t *i2cHardware, uint16_t mainAddress, uint16_t secondAddress);
/**
* @brief Set the i2c Address Lenght, 7 bit or 8 bit, Master or slave doesn't make any difference
* @param i2cHardware is the i2c hardware channel
* @param size Is the Adress isze to be used 7 Bit or 10 Bit
*/
void i2cSetAddressLenght(i2c_t *i2cHardware, i2cAddressSize_t size);
/**
* @brief Stets the Communication speed
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param speed the different awailable speeds
*/
void i2cSetSpeed(i2c_t *i2cHardware, i2cSpeed_t speed);
/**
* @brief Initiates the opperation mode for the selected i2c Channel
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param opperation define if the i2c channel will opperate on pollin, Interrupt, or DMA modes
*/
void i2cSetOpperation(i2c_t *i2cHardware, i2cOpperationMode_t opperation);
/**
* @brief Ebales or disables clock stretching functionalities
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param The value to be written in the register. This will heavily depend on the hardware
*/
void i2cSetClockStretch(i2c_t *i2cHardware, i2cClockStretching_t stretching);
/**
* @brief Set the wakeup mode
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param wake the desider wakeup mode for now i have found only one mode.
*/
void i2cSetWakeup(i2c_t *i2cHardware, i2cWakeUpTypes_t wake);
/**
* @brief Configures Hardware implmente filters if there are any.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
void i2cConfigureFilters(i2c_t *i2cHardware);
/**
* @brief Set the timeout to close the i2c wait time if a communication fails.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param timeout the desider timeout duration in ticks.
*/
void i2cSetTimeout(i2c_t *i2cHardware, uint8_t timeout);
/**
* @brief Resets the i2c Periferal to it's inital state.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
void i2cPeriferalReset(i2c_t *i2cHardware);
/**
* @brief Resets the i2c Harware and register to it's factory deflauts.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
void i2cHardwareReset(i2c_t *i2cHardware);
/**
* @brief Enables I2C Hardware BUS & Clock & Pins
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
void i2cEnableHardware(i2c_t *i2cHardware);
/**
* @brief Enables I2C Periferal core.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
void i2cEnablePeriferal(i2c_t *i2cHardware);
/**
* @brief Disables I2C Periferal core.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
void i2cDisablePeriferal(i2c_t *i2cHardware);
/**************************************************************************************************
I2C Communication functions independen of opperating mode
***************************************************************************************************/
/**
* @brief Writes the given amount of data to the selected device. This function will
* automaticaly choose between i2cMasterSend(); or i2cSlaveSend();
* Depending if the I2C channel was initiated as slave or master.
* this function will adapt himself to the selected oppeartion mode (Polling / Int / DMA)
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param slaveAddress is the address of the device to which the read command will be sent
* @param registerAddress is the regiter to be red from the device
* @param data is the data to be written
* @param dataLenght is the total quantity of 8 bit data to be written.
*/
void i2cWrite(i2c_t *i2cHardware, uint16_t *slaveAddress, uint8_t *registerAddress, uint8_t *data, uint8_t *dataLenght);
/**
* @brief Reads the given amount of data to the selected device. This function will
* automaticaly choose between i2cMasterRecieve(); or i2cSlaveRecieve();
* Depending if the I2C channel was initiated as slave or master.
* this function will adapt himself to the selected oppeartion mode (Polling / Int / DMA)
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param slaveAddress is the address of the device to which the read command will be sent
* @param registerAddress is the regiter to be red from the device
* @param data is the data which has been red
* @paran dataLenght is the total quantity of 8 bit data to be red
*/
void i2cRead(i2c_t *i2cHardware, uint16_t *slaveAddress, uint8_t *registerAddress, uint8_t *data, uint8_t *dataLenght);
/**
* @brief Recieve a Single Byte as master from from the given devices register.
* this function will adapt himself to the selected oppeartion mode (Polling / Int / DMA)
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param slaveAddress is the address of the device to which the read command will be sent
* @param registerAddress is the regiter to be red from the device
* @param data is the data whic has been red
*/
void i2cMasterRecieve(i2c_t *i2cHardware, uint16_t *slaveAddress, uint8_t *registerAddress, uint8_t *data);
/**
* @brief Sends a Single Byte as master to the given devices register.
* this function will adapt himself to the selected oppeartion mode (Polling / Int / DMA)
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param slaveAddress is the address of the device to which the send command will be sent
* @param registerAddress is the regiter to be written to the device
* @param data is the data to be sent
*/
void i2cMasterSend(i2c_t *i2cHardware, uint16_t *slaveAddress, uint8_t *registerAddress, uint8_t *data);
/**
* @brief Recieve a Single Byte as slave from given devices register.
* this function will adapt himself to the selected oppeartion mode (Polling / Int / DMA)
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param slaveAddress is the address of the device to which the read command will be sent
* @param registerAddress is the regiter to be red from the device
* @param data is the data whic has been red
*/
void i2cSlaveRecieve(i2c_t *i2cHardware, uint16_t *slaveAddress, uint8_t *registerAddress, uint8_t *data);
/**
* @brief Recieve a Single Byte as slave from the given devices register.
* this function will adapt himself to the selected oppeartion mode (Polling / Int / DMA)
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param slaveAddress is the address of the device to which the read command will be sent
* @param registerAddress is the regiter to be red from the device
* @param data is the data whic has been red
*/
void i2cSlaveSend(i2c_t *i2cHardware, uint16_t *slaveAddress, uint8_t *registerAddress, uint8_t *data);
/**************************************************************************************************
I2C Hardware functions
***************************************************************************************************/
/**
* @brief Checks if the device is ready for any type of communication
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
void i2cIsPeriferalReady(i2c_t *i2cHardware);
/**
* @brief Generates a Start condition.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
void i2cGenerateStart(i2c_t *i2cHardware);
/**
* @brief Generates a Start condition.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
void i2cGenerateStop(i2c_t *i2cHardware);
/**
* @brief Generates a NACK condition.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
void i2cGenerateNack(i2c_t *i2cHardware);
/**
* @brief Checks If a NACK is recieved.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
uint8_t i2cCheckNack(i2c_t *i2cHardware);
/**
* @brief Generates a ACK condition.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
void i2cGenerateAck(i2c_t *i2cHardware);
/**
* @brief Initiates the communication by sending the slave address on the bus followed by a WRITE
* and waits for an ACK (aknowledge)
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param slaveAddress The address of the slave to be communicated
*/
void i2cSendSlaveAddressWrite(i2c_t *i2cHardware, uint16_t *slaveAddress);
/**
* @brief Initiates the communication by sending the slave address on the bus followed by a READ
* and waits for an ACK (aknowledge)
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param slaveAddress The address of the slave to be communicated
*/
void i2cSendSlaveAddressRead(i2c_t *i2cHardware, uint16_t *slaveAddress);
/**
* @brief Sende the register adrres with which we want to communicate.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param registerAddress The register address of the slave device that we are communication with
*/
void i2cSendRegisterAddress(i2c_t *i2cHardware, uint8_t *registerAddress);
/**
* @brief Send the register that we want to read or write.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param registerAddress the register that need to be accessed
*/
void i2cSendData(i2c_t *i2cHardware, uint8_t *data);
/**
* @brief Initiates a Write command with the previously set slave address.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
void i2cInitiateWriteCommand(i2c_t *i2cHardware);
/**
* @brief Initiates a read command with the previously set slave address.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
void i2cInitiateReadCommand(i2c_t *i2cHardware);
/**
* @brief Is the output buffer empty. This allso meas that the data that was in the ouput buffer
* is sent to the i2c BUS.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
void i2cIsOutputBufferEmpty(i2c_t *i2cHardware);
/**
* @brief Is the output buffer empty. This allso meas that the data that was in the ouput buffer
* is sent to the i2c BUS.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
void i2cIsInputBufferEmpty(i2c_t *i2cHardware);
/**
* @brief reads the I2C input buffer
* is sent to the i2c BUS.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param data pointer to the data that need to be read and returned
*/
void i2cReadInputRegister(i2c_t *i2cHardware, uint8_t *data);
/**
* @brief writes to the I2C output buffer
* is sent to the i2c BUS.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param data pointer to the data that need to be read and returned
*/
void i2cSetOutputRegister(i2c_t *i2cHardware, uint8_t *data);
/**
* @brief Checks is transfer is complete
* is sent to the i2c BUS.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param data pointer to the data that need to be read and returned
*/
void i2cIsTransferComplete(i2c_t *i2cHardware);
/**
* @brief Defines the amount of transfers to be made. Address exchange and start conditon does not count
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param count amount o data to be transfered.
*/
void i2cSetTransferCounter(i2c_t *i2cHardware, uint8_t count);
/**************************************************************************************************
I2C Communication functions Polling / Blocking Mode
***************************************************************************************************/
/**
* @brief Recieve a Single Byte in polling mode as master from from the given devices register.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param slaveAddress is the address of the device to which the read command will be sent
* @param registerAddress is the regiter to be red from the device
* @param data is the data whic has been red
*/
void i2cMasterRecievePolling(i2c_t *i2cHardware, uint16_t *slaveAddress, uint8_t *registerAddress, uint8_t *data);
/**
* @brief Sends a Single Byte in polling mode as master to the given devices register.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param slaveAddress is the address of the device to which the send command will be sent
* @param registerAddress is the regiter to be written to the device
* @param data is the data to be sent
*/
void i2cMasterSendPolling(i2c_t *i2cHardware, uint16_t *slaveAddress, uint8_t *registerAddress, uint8_t *data);
/**
* @brief Recieve a Single Byte in polling mide as slave from the given devices register.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param slaveAddress is the address of the device to which the read command will be sent
* @param registerAddress is the regiter to be red from the device
* @param data is the data whic has been red
*/
void i2cSlaveRecievePolling(i2c_t *i2cHardware, uint16_t *slaveAddress, uint8_t *registerAddress, uint8_t *data);
/**
* @brief Recieve a Single Byte in polling mode as slave from the given devices register.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param slaveAddress is the address of the device to which the read command will be sent
* @param registerAddress is the regiter to be red from the device
* @param data is the data whic has been red
*/
void i2cSlaveSendPolling(i2c_t *i2cHardware, uint16_t *slaveAddress, uint8_t *registerAddress, uint8_t *data);
/**************************************************************************************************
I2C Arbitration Functions for Multymaster mode and slaves clock stretching
***************************************************************************************************/
void i2cClockSynchronise(); // I2C Standart : Clock Syncronization
void i2cAbortTransmit(); // I2c Standart : Stop Communication for multimaster mode
void i2cArbitration(); // I2C Standart : Arbitration for multimaster mode to define the right master.
void i2cSoftReset(); // I2C Standart : Software reset not supported by all hardware.
void i2cBusClear(); // I2C Standart : in case if SCL is stuck
/**************************************************************************************************
I2C Extra functions that are not esential for the main functionality
***************************************************************************************************/
/**
* @brief This function will scan every for possible addresses to discover devices on the bus.
* And write them to the Devices list given to him. This function will not discover more
* devices than what he is told.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param devices list where the discevered devices will be written
* @param deviceCount Max number of devices to be discovered.
*/
void i2cDiscoverDevices(i2c_t *i2cHardware, uint16_t *devices, uint8_t deviceCount);
/**
* @brief This function will try to communicate with a device with every speed
* allowed by his hardware to find out the maximum communication sppeed possible.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param slaveAddress is the address of the device to which the read command will be sent
*/
i2cSpeed_t i2cTestDeviceSpeed(i2c_t *i2cHardware, uint16_t *slaveAddress);
/**
* @brief This function will read the device info register (if awailable) as follows :
* I2c Standart : 3 Bytes (24 bits) | 12 Bits : Manufacturer info | 9 Bits: Part Identification | 3 Bits DIE Rev.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
* @param slaveAddress is the address of the device to be red
*/
uint32_t i2cReadDeviceInfo(i2c_t *i2cHardware, uint16_t *slaveAddress);
/**
* @brief The selected i2c channel is put on sleep.
* @param i2cHardware is the beforehand declared i2c channel with his opperation modes
*/
void i2cSleep(i2c_t *i2cHardware);
/**
* @brief Error handling.
* @param error The error no generated.
*/
void i2cThrowError(i2c_t *i2cHardware, int16_t error);
#ifdef __cplusplus
}
#endif
#endif // _I2C_H_

@ -3,7 +3,7 @@ CSL_TO_USE=$1
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
PROJECT_DIR=$SCRIPT_DIR/..
CMAKE_DIR=$SCRIPT_DIR
BUILD_DIR=$SCRIPT_DIR/../ked_build
cd $SCRIPT_DIR
@ -44,8 +44,8 @@ build()
fi
done
else
else
cd $CMAKE_DIR
if [ -d "$BUILD_DIR" ];then
rm -r $BUILD_DIR
cmake -S . -B $BUILD_DIR -DCSL_USED=$CSL_TO_USE
@ -54,7 +54,7 @@ build()
fi
cd $BUILD_DIR
make -j4
make -j8
if [ "$CSL_TO_USE" == "raspberry" ];then
echo -e "\e[36m"

Loading…
Cancel
Save