-
Notifications
You must be signed in to change notification settings - Fork 1
/
lcd_pcd8544_ll.c
116 lines (99 loc) · 4.38 KB
/
lcd_pcd8544_ll.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* lcd_pcd8544_ll.c
*
* Created on: May 4, 2019
* Author: evovch
*/
#include "lcd_pcd8544_ll.h"
// =============================================================================
HAL_StatusTypeDef LCD_PCD8544_LL_send_data(LCD_PCD8544_screen_t* scr, unsigned char* bytes, unsigned short int nBytes)
{
HAL_StatusTypeDef stat = HAL_SPI_Transmit(scr->mPinout.mSpiHandle, bytes, nBytes, SPI_TIMEOUT);
if (stat != HAL_OK) {
HAL_GPIO_WritePin(scr->mPinout.mLcdErrorLedPort, scr->mPinout.mLcdErrorLedPin, GPIO_PIN_RESET);
}
return stat;
}
HAL_StatusTypeDef LCD_PCD8544_LL_send_byte(LCD_PCD8544_screen_t* scr, unsigned char byte)
{
unsigned short int nBytes = 1;
return LCD_PCD8544_LL_send_data(scr, &byte, nBytes);
}
// =============================================================================
// H=0 or H=1
// =============================================================================
HAL_StatusTypeDef LCD_PCD8544_LL_set_function_set(LCD_PCD8544_screen_t* scr, unsigned char pd, unsigned char v, unsigned char h)
{
//TODO check that pd argument is within the limits
//TODO check that v argument is within the limits
//TODO check that h argument is within the limits
// Also, probably, implement proper error handling
unsigned char command = (1 << 5) | ((pd & 0x01) << 2) | ((v & 0x01) << 1) | (h & 0x1);
return LCD_PCD8544_LL_send_byte(scr, command);
}
HAL_StatusTypeDef LCD_PCD8544_LL_write_data(LCD_PCD8544_screen_t* scr, unsigned char d)
{
//TODO check that d argument is within the limits
// Also, probably, implement proper error handling
return LCD_PCD8544_LL_send_byte(scr, d);
}
// =============================================================================
// H=0
// =============================================================================
HAL_StatusTypeDef LCD_PCD8544_LL_set_display_control(LCD_PCD8544_screen_t* scr, unsigned char d, unsigned char e)
{
//TODO check that d argument is within the limits
//TODO check that e argument is within the limits
// Also, probably, implement proper error handling
unsigned char command = (1 << 3) | ((d & 0x01) << 2) | (e & 0x01);
return LCD_PCD8544_LL_send_byte(scr, command);
}
HAL_StatusTypeDef LCD_PCD8544_LL_set_Y_address_of_RAM(LCD_PCD8544_screen_t* scr, unsigned char y)
{
//TODO check that y argument is within the limits
// Also, probably, implement proper error handling
unsigned char command = (1 << 6) | (y & 0x07);
return LCD_PCD8544_LL_send_byte(scr, command);
}
HAL_StatusTypeDef LCD_PCD8544_LL_set_X_address_of_RAM(LCD_PCD8544_screen_t* scr, unsigned char x)
{
//TODO check that x argument is within the limits
// Also, probably, implement proper error handling
unsigned char command = (1 << 7) | (x & 0x7f);
return LCD_PCD8544_LL_send_byte(scr, command);
}
HAL_StatusTypeDef LCD_PCD8544_LL_set_YX_address_of_RAM(LCD_PCD8544_screen_t* scr, unsigned char y, unsigned char x)
{
//TODO check that y argument is within the limits
//TODO check that x argument is within the limits
// Also, probably, implement proper error handling
unsigned char commands[2];
commands[0] = (1 << 6) | (y & 0x07);
commands[1] = (1 << 7) | (x & 0x7f);
return LCD_PCD8544_LL_send_data(scr, commands, 2);
}
// =============================================================================
// H=1
// =============================================================================
HAL_StatusTypeDef LCD_PCD8544_LL_set_temperature_control(LCD_PCD8544_screen_t* scr, unsigned char tc)
{
//TODO check that tc argument is within the limits
// Also, probably, implement proper error handling
unsigned char command = (1 << 2) | (tc & 0x03);
return LCD_PCD8544_LL_send_byte(scr, command);
}
HAL_StatusTypeDef LCD_PCD8544_LL_set_bias_system(LCD_PCD8544_screen_t* scr, unsigned char bs)
{
//TODO check that bs argument is within the limits
// Also, probably, implement proper error handling
unsigned char command = (1 << 4) | (bs & 0x07);
return LCD_PCD8544_LL_send_byte(scr, command);
}
HAL_StatusTypeDef LCD_PCD8544_LL_set_VOP(LCD_PCD8544_screen_t* scr, unsigned char vop)
{
//TODO check that vop argument is within the limits
// Also, probably, implement proper error handling
unsigned char command = (1 << 7) | (vop & 0x7f);
return LCD_PCD8544_LL_send_byte(scr, command);
}
// =============================================================================