Commit ca3aaa55 authored by schneider's avatar schneider

chore(display,portexpander): style

parent a76880e9
......@@ -9,7 +9,7 @@
#include <stdint.h>
#include <stdio.h>
/***** Globals *****/
const gpio_cfg_t DEV_DC_PIN = {PORT_1, PIN_6, GPIO_FUNC_OUT, GPIO_PAD_NONE};
const gpio_cfg_t DEV_DC_PIN = { PORT_1, PIN_6, GPIO_FUNC_OUT, GPIO_PAD_NONE };
// Parameters for PWM output
#define PORT_PWM PORT_0 // port
......@@ -19,7 +19,6 @@ const gpio_cfg_t DEV_DC_PIN = {PORT_1, PIN_6, GPIO_FUNC_OUT, GPIO_PAD_NONE};
#define DUTY_CYCLE 20 // (%)
#define PWM_TIMER MXC_TMR4 // must change PORT_PWM and PIN_PWM if changed
/***** Functions *****/
void PWM_Output(void)
{
......@@ -73,8 +72,8 @@ void PWM_Output(void)
void display_set_reset_pin(uint8_t state)
{
if(!portexpander_detected()) {
MAX77650_setDO(state ? true:false);
if (!portexpander_detected()) {
MAX77650_setDO(state ? true : false);
} else {
portexpander_set(4, state);
}
......@@ -82,7 +81,7 @@ void display_set_reset_pin(uint8_t state)
void display_init(void)
{
if(!portexpander_detected()) {
if (!portexpander_detected()) {
// Open-drain
MAX77650_setDRV(false);
// Output
......@@ -96,7 +95,7 @@ void display_init(void)
LCD_Init();
LCD_Clear(BLACK);
Paint_NewImage(LCD_WIDTH, LCD_HEIGHT,0,WHITE);
Paint_NewImage(LCD_WIDTH, LCD_HEIGHT, 0, WHITE);
Paint_Clear(BLACK);
Paint_SetRotate(180);
......
......@@ -16,10 +16,10 @@ void portexpander_init(void)
int ret;
// Enable pull-ups for buttons
uint8_t command[] = {0x43, 0x68};
uint8_t command[] = { 0x43, 0x68 };
ret = I2C_MasterWrite(MXC_I2C1_BUS0, addr << 1, command, 2, 0);
if(ret != 2) {
if (ret != 2) {
printf("portexpander NOT detected\n");
detected = false;
return;
......@@ -27,32 +27,35 @@ void portexpander_init(void)
detected = true;
// Set _all_ outputs to open-drain to support the high side p-channel transistors.
command[0] = 0x4F; command[1] = 0x01;
command[0] = 0x4F;
command[1] = 0x01;
I2C_MasterWrite(MXC_I2C1_BUS0, addr << 1, command, 2, 0);
// Enable outputs for the transistors, the LED and the LCD reset
command[0] = 0x03; command[1] = 0x68;
command[0] = 0x03;
command[1] = 0x68;
I2C_MasterWrite(MXC_I2C1_BUS0, addr << 1, command, 2, 0);
// Set outputs to high (i.e. open-drain)
output_state = 0x97;
command[0] = 0x01; command[1] = output_state;
command[0] = 0x01;
command[1] = output_state;
I2C_MasterWrite(MXC_I2C1_BUS0, addr << 1, command, 2, 0);
// Turn on LEDs
// TODO: only turn on LEDs if value != 0,0,0 && dim > 0
command[0] = 0x01; command[1] = 0x90;
command[0] = 0x01;
command[1] = 0x90;
I2C_MasterWrite(MXC_I2C1_BUS0, addr << 1, command, 2, 0);
}
uint8_t portexpander_get(void)
{
uint8_t addr = 0x21;
uint8_t command[] = {0x00};
uint8_t command[] = { 0x00 };
uint8_t buf = 0xFF;
if(detected) {
if (detected) {
I2C_MasterWrite(MXC_I2C1_BUS0, addr << 1, command, 1, 1);
I2C_MasterRead(MXC_I2C1_BUS0, addr << 1, &buf, 1, 0);
}
......@@ -70,14 +73,15 @@ void portexpander_set(uint8_t pin, uint8_t value)
uint8_t addr = 0x21;
uint8_t command[2];
if(detected && pin < 8) {
if(value) {
if (detected && pin < 8) {
if (value) {
output_state |= (1 << pin);
} else {
output_state &= ~(1 << pin);
}
command[0] = 0x01; command[1] = output_state;
command[0] = 0x01;
command[1] = output_state;
I2C_MasterWrite(MXC_I2C1_BUS0, addr << 1, command, 2, 0);
}
}
......@@ -62,16 +62,16 @@ function:
void LCD_WriteData_Byte(UBYTE da)
{
//DEV_Digital_Write(DEV_CS_PIN,0);
DEV_Digital_Write(DEV_DC_PIN,1);
DEV_Digital_Write(DEV_DC_PIN, 1);
DEV_SPI_WRITE(da);
//DEV_Digital_Write(DEV_CS_PIN,1);
}
void LCD_WriteData_Word(UWORD da)
void LCD_WriteData_Word(UWORD da)
{
UBYTE i=(da>>8)&0xff;
UBYTE i = (da >> 8) & 0xff;
//DEV_Digital_Write(DEV_CS_PIN,0);
DEV_Digital_Write(DEV_DC_PIN,1);
DEV_Digital_Write(DEV_DC_PIN, 1);
DEV_SPI_WRITE(i);
uint8_t tmp = da;
DEV_SPI_WRITE(tmp);
......@@ -81,7 +81,7 @@ void LCD_WriteData_Byte(UBYTE da)
void LCD_WriteReg(UBYTE da)
{
//DEV_Digital_Write(DEV_CS_PIN,0);
DEV_Digital_Write(DEV_DC_PIN,0);
DEV_Digital_Write(DEV_DC_PIN, 0);
DEV_SPI_WRITE(da);
//DEV_Digital_Write(DEV_CS_PIN,1);
}
......@@ -95,8 +95,8 @@ void LCD_Init(void)
LCD_Reset();
//************* Start Initial Sequence **********//
LCD_WriteReg(0x11);//Sleep exit
DEV_Delay_ms (120);
LCD_WriteReg(0x11); //Sleep exit
DEV_Delay_ms(120);
LCD_WriteReg(0x21);
LCD_WriteReg(0x21);
......@@ -184,7 +184,7 @@ void LCD_Init(void)
LCD_WriteData_Byte(0x05);
LCD_WriteReg(0x36);
LCD_WriteData_Byte(0xA8);//
LCD_WriteData_Byte(0xA8); //
LCD_WriteReg(0x29);
}
......@@ -202,17 +202,17 @@ void LCD_SetCursor(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend)
Xstart = Xstart + 1;
Xend = Xend + 1;
Ystart = Ystart + 26;
Yend = Yend+26;
Yend = Yend + 26;
LCD_WriteReg(0x2a);
LCD_WriteData_Byte(Xstart>>8);
LCD_WriteData_Byte(Xstart >> 8);
LCD_WriteData_Byte(Xstart);
LCD_WriteData_Byte(Xend >>8);
LCD_WriteData_Byte(Xend );
LCD_WriteData_Byte(Xend >> 8);
LCD_WriteData_Byte(Xend);
LCD_WriteReg(0x2b);
LCD_WriteData_Byte(Ystart>>8);
LCD_WriteData_Byte(Ystart >> 8);
LCD_WriteData_Byte(Ystart);
LCD_WriteData_Byte(Yend>>8);
LCD_WriteData_Byte(Yend >> 8);
LCD_WriteData_Byte(Yend);
LCD_WriteReg(0x2C);
......@@ -244,12 +244,13 @@ parameter :
Yend : End UWORD coordinates
color : Set the color
******************************************************************************/
void LCD_ClearWindow(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend,UWORD color)
{
UWORD i,j;
LCD_SetCursor(Xstart, Ystart, Xend-1,Yend-1);
for(i = Ystart; i <= Yend-1; i++){
for(j = Xstart; j <= Xend-1; j++){
void LCD_ClearWindow(
UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD color
) {
UWORD i, j;
LCD_SetCursor(Xstart, Ystart, Xend - 1, Yend - 1);
for (i = Ystart; i <= Yend - 1; i++) {
for (j = Xstart; j <= Xend - 1; j++) {
LCD_WriteData_Word(color);
}
}
......@@ -264,9 +265,10 @@ parameter :
Yend : End UWORD coordinates
Color : Set the color
******************************************************************************/
void LCD_SetWindowColor(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend,UWORD Color)
{
LCD_SetCursor( Xstart,Ystart,Xend,Yend);
void LCD_SetWindowColor(
UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color
) {
LCD_SetCursor(Xstart, Ystart, Xend, Yend);
LCD_WriteData_Word(Color);
}
......@@ -293,9 +295,9 @@ void LCD_SetUWORD(UWORD x, UWORD y, UWORD Color)
void LCD_Clear(UWORD Color)
{
UWORD i,j;
for(i = 0; i < LCD_WIDTH; i++){
for(j = 0; j < LCD_HEIGHT; j++){
UWORD i, j;
for (i = 0; i < LCD_WIDTH; i++) {
for (j = 0; j < LCD_HEIGHT; j++) {
LCD_SetUWORD(i, j, Color);
}
}
......@@ -303,13 +305,12 @@ void LCD_Clear(UWORD Color)
void LCD_Set(uint8_t *data, int len)
{
LCD_SetCursor(0,0,160-1,80-1);
DEV_Digital_Write(DEV_DC_PIN,1);
LCD_SetCursor(0, 0, 160 - 1, 80 - 1);
DEV_Digital_Write(DEV_DC_PIN, 1);
lcd_write(data, len);
}
void LCD_Update(void)
{
LCD_Set((uint8_t*)screen, sizeof(screen));
LCD_Set((uint8_t *)screen, sizeof(screen));
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment