stm32-camera  1.0
st7735r.c
Go to the documentation of this file.
1 /**
2  * @file st7735r.c
3  * @brief Main source file for the ST7735R LCD chip.
4  * @details pinkeee @ j.t0dd@protonmail.com
5  * @note See README for contributing guides and info.
6  * @copyright See License file.
7  */
8 
9 #include "st7735r.h"
10 
11 /**
12  * @brief Set SPI1 CS pin
13  * @param Void
14  * @return Void N/A
15 */
16 void ST7735R_CS_High(void)
17 {
18  HAL_GPIO_WritePin(SPI1_CS_GPIO_Port, SPI1_CS_Pin, GPIO_PIN_SET);
19 }
20 
21 /**
22  * @brief Bring low SPI1 CS pin
23  * @param Void
24  * @return Void N/A
25 */
26 void ST7735R_CS_Low(void)
27 {
28  HAL_GPIO_WritePin(SPI1_CS_GPIO_Port, SPI1_CS_Pin, GPIO_PIN_RESET);
29 }
30 
31 /**
32  * @brief Write command on device
33  * @param cmd what command to write to
34  * @return either ST7735R_RET_OK or ST7735R_RET_FAIL
35  */
36 ST7735R_Return ST7735R_Write_Command(struct ST7735R *self, uint8_t cmd)
37 {
38  HAL_GPIO_WritePin(A0_GPIO_Port, A0_Pin, GPIO_PIN_RESET);
39 
41  if (HAL_SPI_Transmit(self->SPI_Handler, &cmd, sizeof(cmd), ST7735R_SPI_TIMEOUT) != HAL_OK)
42  {
44  return ST7735R_RET_FAIL;
45  }
47  return ST7735R_RET_OK;
48 }
49 
50 /**
51  * @brief Write data to RAM on device
52  * @param data what command to write to
53  * @param size size of data buffer
54  * @return either ST7735R_RET_OK or ST7735R_RET_FAIL
55  */
56 ST7735R_Return ST7735R_Write_Data(struct ST7735R *self, uint8_t *data, uint8_t size)
57 {
58  HAL_GPIO_WritePin(A0_GPIO_Port, A0_Pin, GPIO_PIN_SET);
59 
61  if (HAL_SPI_Transmit(self->SPI_Handler, data, size, ST7735R_SPI_TIMEOUT) != HAL_OK)
62  {
64  return ST7735R_RET_FAIL;
65  }
67  return ST7735R_RET_OK;
68 }
69 
70 /**
71  * @brief Turn backlight off
72  * @return either ST7735R_RET_OK or ST7735R_RET_FAIL
73  */
75 {
76  uint8_t tx[2] = {0};
77  uint8_t rx[10] = {0};
78 
79  tx[0] = ST7735R_DISPOFF_CMD;
80 
82  HAL_GPIO_WritePin(A0_GPIO_Port, A0_Pin, GPIO_PIN_RESET);
83 
84  HAL_SPI_Transmit(self->SPI_Handler, tx, sizeof(tx), 100);
85  //HAL_SPI_Receive(self->SPI_Handler, rx, 4, 100);
87 
88  return ST7735R_RET_OK;
89 }
static uint8_t ST7735R_DISPOFF_CMD
DISPOFF command.
Definition: st7735r.h:139
ST7735R_Return ST7735R_Write_Command(struct ST7735R *self, uint8_t cmd)
Write command on device.
Definition: st7735r.c:36
void ST7735R_CS_Low(void)
Bring low SPI1 CS pin.
Definition: st7735r.c:26
#define ST7735R_RET_OK
Definition: st7735r.h:15
#define ST7735R_RET_FAIL
Definition: st7735r.h:16
int ST7735R_Return
Definition: st7735r.h:269
#define ST7735R_SPI_TIMEOUT
Definition: st7735r.h:18
ST7735R_Return ST7735R_Backlight_Off(struct ST7735R *self)
Turn backlight off.
Definition: st7735r.c:74
void ST7735R_CS_High(void)
Set SPI1 CS pin.
Definition: st7735r.c:16
Main header file for the ST7735R LCD chip.
ST7735R_Return ST7735R_Write_Data(struct ST7735R *self, uint8_t *data, uint8_t size)
Write data to RAM on device.
Definition: st7735r.c:56