i2c is working beter and added a check device funtion who checks is a device is on the bu or not. Driver header in cmake were not correctly included, i have fixed that issue too
parent
0e22b6b379
commit
4030ed9611
@ -1 +1 @@
|
|||||||
set(DRIVERS_LIST max7219 max31865)
|
set(DRIVERS_LIST pf8574 max7219 max31865)
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
add_library(MAX31865 max31865.c)
|
|
||||||
target_compile_options(MAX31865 PRIVATE ${C_FLAGS})
|
|
||||||
target_compile_definitions(MAX31865 PRIVATE ${C_DEFS})
|
|
||||||
target_include_directories(MAX31865 PUBLIC . ${PERIFERALS_DIR} ${CSL_INCLUDES})
|
|
||||||
add_library(sub::max31865 ALIAS MAX31865)
|
|
@ -1,5 +0,0 @@
|
|||||||
add_library(MAX7219 max7219.c)
|
|
||||||
target_compile_options(MAX7219 PRIVATE ${C_FLAGS})
|
|
||||||
target_compile_definitions(MAX7219 PRIVATE ${C_DEFS})
|
|
||||||
target_include_directories(MAX7219 PUBLIC . ${PERIFERALS_DIR} ${CSL_INCLUDES})
|
|
||||||
add_library(sub::max7219 ALIAS MAX7219)
|
|
@ -0,0 +1,123 @@
|
|||||||
|
//////////////////////////////////////////////////////////
|
||||||
|
// Created by : Kerem Yollu
|
||||||
|
// Project : Multiprise conectée
|
||||||
|
// Nom : lcd.c
|
||||||
|
// Header : lcd.h
|
||||||
|
//_________________________Info_________________________
|
||||||
|
//
|
||||||
|
// Libraire pour le control d'un ecran lcd stadard (HD44780)
|
||||||
|
// controlée par un expandeur de port PCF8574 en I2C.
|
||||||
|
//
|
||||||
|
//////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include "pf8574.h"
|
||||||
|
|
||||||
|
// Fonction pour initialiser l'écran vide en mode 4 bits
|
||||||
|
uint16_t lcd_init(i2c_t *i2c_dev)
|
||||||
|
{
|
||||||
|
lcd_write(i2c_dev,0x03,CMD_MODE); // Mise en mode 4 bit avec 4 essai conssecutif
|
||||||
|
lcd_write(i2c_dev,0x03,CMD_MODE);
|
||||||
|
lcd_write(i2c_dev,0x03,CMD_MODE);
|
||||||
|
lcd_write(i2c_dev,0x02,CMD_MODE);
|
||||||
|
lcd_write(i2c_dev,LCD_FUNCTIONSET | LCD_2LINE | LCD_5x8DOTS | LCD_4BITMODE ,CMD_MODE);
|
||||||
|
lcd_write(i2c_dev,LCD_DISPLAYCONTROL | LCD_DISPLAYON ,CMD_MODE);
|
||||||
|
lcd_write(i2c_dev,LCD_CLEARDISPLAY ,CMD_MODE);
|
||||||
|
lcd_write(i2c_dev,LCD_ENTRYMODESET | LCD_ENTRYLEFT ,CMD_MODE);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Fonction qui vas afficher une pharse sur la ligne et colone qui lui est indiquée
|
||||||
|
// Attention la fonction est capable de calculer la liongeure d0ubn phrase mais il ne
|
||||||
|
// faut pas dépasser la limite d'une ligne totale qui est de 20 charactères max
|
||||||
|
//
|
||||||
|
// LCD 20x4
|
||||||
|
// -------------------------------------------
|
||||||
|
// ||# # # # # # # # # # # # # # # # # # # #||
|
||||||
|
// ||# # # # # # # # # # # # # # # # # # # #||
|
||||||
|
// ||# # # # # # # # # # # # # # # # # # # #||
|
||||||
|
// ||# # # # # # # # # # # # # # # # # # # #||
|
||||||
|
// -------------------------------------------
|
||||||
|
void lcd_display_string(i2c_t *i2c_dev, uint8_t line, uint8_t pos, uint8_t* charvalue, uint8_t lenght)
|
||||||
|
{
|
||||||
|
uint8_t setPosition = 0;
|
||||||
|
uint16_t i, S_length = 0;
|
||||||
|
|
||||||
|
S_length = lenght;
|
||||||
|
if (S_length > TOTAL_CHAR_CAP)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(line == 1) // Selection de la ligne d'écriture
|
||||||
|
{
|
||||||
|
setPosition = pos;
|
||||||
|
}
|
||||||
|
else if(line ==2)
|
||||||
|
{
|
||||||
|
setPosition = 0x40 + pos;
|
||||||
|
}
|
||||||
|
else if(line ==3)
|
||||||
|
{
|
||||||
|
setPosition = 0x14 + pos;
|
||||||
|
}
|
||||||
|
else if(line ==4)
|
||||||
|
{
|
||||||
|
setPosition = 0x54 + pos;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
setPosition = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(setPosition >= 0)
|
||||||
|
{
|
||||||
|
lcd_write(i2c_dev, LCD_SETDDRAMADDR + setPosition, CMD_MODE);
|
||||||
|
|
||||||
|
for(i = 0; i < lenght; i++ )
|
||||||
|
{
|
||||||
|
lcd_write(i2c_dev,charvalue[i],RS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Cette fonction nous permet d'envoyer un information de 8 bits sous format
|
||||||
|
// de 2x4 bites. Celà est necessaire du au fonctionnement de l'expendeur de port PCF8574
|
||||||
|
// qui est branché sur l'écran de facon a ce qu'il communiquer en 4 bits.
|
||||||
|
void lcd_write(i2c_t *i2c_dev, uint8_t cmd, uint8_t mode)
|
||||||
|
{
|
||||||
|
lcd_write_4bits(i2c_dev, mode | (cmd & 0xF0));
|
||||||
|
lcd_write_4bits(i2c_dev, mode | ((cmd << 4) & 0xF0));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fonction nous permettant d'nevoyer 4 bits dinformation sur le PC8574 ainsi que
|
||||||
|
// le rétroéclairage.
|
||||||
|
void lcd_write_4bits(i2c_t *i2c_dev,uint8_t data)
|
||||||
|
{
|
||||||
|
uint16_t address = LCD_ADDRS;
|
||||||
|
uint8_t i2c_data = 0;
|
||||||
|
|
||||||
|
i2c_set_transfer_counter(i2c_dev,3);
|
||||||
|
i2c_send_address_for_write(i2c_dev, &address);
|
||||||
|
|
||||||
|
i2c_data = data | LCD_BACKLIGHT;
|
||||||
|
i2c_send_data(i2c_dev, &i2c_data);
|
||||||
|
|
||||||
|
// Toggle LCD enbale pin.
|
||||||
|
i2c_data = data | EN |LCD_BACKLIGHT;
|
||||||
|
i2c_send_data(i2c_dev, &i2c_data);
|
||||||
|
delayMs(100);
|
||||||
|
|
||||||
|
i2c_data = ((data & ~EN) | LCD_BACKLIGHT);
|
||||||
|
i2c_send_data(i2c_dev, &i2c_data);
|
||||||
|
|
||||||
|
while(!i2c_is_transfer_complete(i2c_dev));
|
||||||
|
i2c_send_stop(i2c_dev);
|
||||||
|
|
||||||
|
delayMs(500);
|
||||||
|
}
|
@ -0,0 +1,94 @@
|
|||||||
|
/**
|
||||||
|
**************************************************************************************************
|
||||||
|
* @file max7219.h
|
||||||
|
* @author Kerem Yollu & Edwin Koch
|
||||||
|
* @date 25.08.2022
|
||||||
|
* @version 1.0
|
||||||
|
**************************************************************************************************
|
||||||
|
* @brief
|
||||||
|
*
|
||||||
|
* **Detailed Description :**
|
||||||
|
*
|
||||||
|
* @todo
|
||||||
|
**************************************************************************************************
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _PF8574_H_
|
||||||
|
#define _PF8574_H_
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "i2c.h"
|
||||||
|
#include "delay.h"
|
||||||
|
|
||||||
|
#define LCD_CLEARDISPLAY 0x01
|
||||||
|
#define LCD_RETURNHOME 0x02
|
||||||
|
#define LCD_ENTRYMODESET 0x04
|
||||||
|
#define LCD_DISPLAYCONTROL 0x08
|
||||||
|
#define LCD_CURSORSHIFT 0x10
|
||||||
|
#define LCD_FUNCTIONSET 0x20
|
||||||
|
#define LCD_SETCGRAMADDR 0x40
|
||||||
|
#define LCD_SETDDRAMADDR 0x80
|
||||||
|
|
||||||
|
// flags pour mode d'ecriture
|
||||||
|
#define LCD_ENTRYRIGHT 0x00
|
||||||
|
#define LCD_ENTRYLEFT 0x02
|
||||||
|
#define LCD_ENTRYSHIFTINCREMENT 0x01
|
||||||
|
#define LCD_ENTRYSHIFTDECREMENT 0x00
|
||||||
|
|
||||||
|
// flags pour ecran on/off control
|
||||||
|
#define LCD_DISPLAYON 0x04
|
||||||
|
#define LCD_DISPLAYOFF 0x00
|
||||||
|
#define LCD_CURSORON 0x02
|
||||||
|
#define LCD_CURSOROFF 0x00
|
||||||
|
#define LCD_BLINKON 0x01
|
||||||
|
#define LCD_BLINKOFF 0x00
|
||||||
|
|
||||||
|
// flags pour display/decalage curseurr
|
||||||
|
#define LCD_DISPLAYMOVE 0x08
|
||||||
|
#define LCD_CURSORMOVE 0x00
|
||||||
|
#define LCD_MOVERIGHT 0x04
|
||||||
|
#define LCD_MOVELEFT 0x00
|
||||||
|
|
||||||
|
// flags pour function set
|
||||||
|
#define LCD_8BITMODE 0x10
|
||||||
|
#define LCD_4BITMODE 0x00
|
||||||
|
#define LCD_2LINE 0x08
|
||||||
|
#define LCD_1LINE 0x00
|
||||||
|
#define LCD_5x1DOTS 0x04
|
||||||
|
#define LCD_5x8DOTS 0x00
|
||||||
|
|
||||||
|
//flags pour le rétroeclairage
|
||||||
|
#define LCD_BACKLIGHT 0x08
|
||||||
|
#define LCD_NOBACKLIGHT 0x00
|
||||||
|
|
||||||
|
//Pins de gestion de donées.
|
||||||
|
#define EN 0x04 // Enable bit
|
||||||
|
#define RW 0x02 // Read/Write bit
|
||||||
|
#define RS 0x01 // Register select bit
|
||||||
|
|
||||||
|
|
||||||
|
//DIfferents mode enre commande est ecriture
|
||||||
|
#define CMD_MODE 0x00
|
||||||
|
#define CHAR_MODE 0x01
|
||||||
|
|
||||||
|
//adresse I2C du controlleur pour LCD
|
||||||
|
#define LCD_ADDRS 0x27
|
||||||
|
|
||||||
|
//Nombre max de uint8_t sur une ligne
|
||||||
|
#define TOTAL_CHAR_CAP 20
|
||||||
|
|
||||||
|
uint16_t lcd_init(i2c_t *i2c_dev);
|
||||||
|
void lcd_write_char(i2c_t *i2c_dev, uint8_t charvalue);
|
||||||
|
void lcd_display_string(i2c_t *i2c_dev, uint8_t line, uint8_t pos, uint8_t* charvalue, uint8_t lenght);
|
||||||
|
void lcd_write(i2c_t *i2c_dev, uint8_t cmd, uint8_t mode);
|
||||||
|
void lcd_write_4bits(i2c_t *i2c_de, uint8_t data);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* MAIN_H */
|
||||||
|
|
Loading…
Reference in new issue