IoT-MBBR (masterthesis)
Masterthesis upgrading a Moving Bed BioReactor with extra sensors and cloud connectivity.
serlcd.h File Reference

serLCD functionality. More...

#include <stdint.h>
#include <stdbool.h>

Go to the source code of this file.

Functions

int8_t clearLCD (void)
 Clear the LCD. More...
 
int8_t writeCharLCD (uint8_t data)
 Write a character (one byte) to the LCD. More...
 
int8_t writeStringLCD (char *message)
 Print a string (char array) to the LCD. More...
 
int8_t setCursorLCD (uint8_t col, uint8_t row)
 Set the cursor to a specific location on the LCD. More...
 
int8_t heartBeatLCD (void)
 Update the heartbeat icon. More...
 

Detailed Description

serLCD functionality.

Version
1.0
Author
Brecht Van Eeckhoudt

License

Copyright (C) 2020 - Brecht Van Eeckhoudt

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

A copy of the GNU General Public License can be found in the LICENSE file along with this source code.


Some methods use code obtained from examples from Silicon Labs' GitHub. These sections are licensed under the Silabs License Agreement. See the file "Silabs_License_Agreement.txt" for details. Before using this software for any purpose, you must agree to the terms of that agreement.


Code based on: https://github.com/sparkfun/SparkFun_SerLCD_Arduino_Library/blob/master/src/SerLCD.cpp

Definition in file serlcd.h.

Function Documentation

◆ clearLCD()

int8_t clearLCD ( void  )

Clear the LCD.

This method also initializes i2C if necessary.

Returns
  • 0 - Byte written correctly.
  • -1 - i2cTransferNack, NACK received during transfer.
  • -2 - i2cTransferBusErr, Bus error during transfer (misplaced START/STOP).
  • -3 - i2cTransferArbLost, Arbitration lost during transfer.
  • -4 - i2cTransferUsageFault, Usage fault.
  • -5 - i2cTransferSwFault, SW fault.
  • -6 - Coudldn't configure I2C.

Definition at line 168 of file serlcd.c.

169 {
170  /* Initialize I2C if not already the case */
171  if (initI2C() != 0) return (-6);
172 
173  /* Put commands in array */
174  uint8_t data_buf[2] = {SETTING_COMMAND, CLEAR_COMMAND};
175 
176  /* Transfer structure */
177  I2C_TransferSeq_TypeDef i2cTransfer;
178  I2C_TransferReturn_TypeDef result;
179 
180  /* Initializing I2C transfer */
181  i2cTransfer.addr = DISPLAY_ADDRESS << 1; /* Left shift so we go to 8 bit notation instead of 7 */
182  i2cTransfer.flags = I2C_FLAG_WRITE; /* Data written from buf[0].data */
183  i2cTransfer.buf[0].data = data_buf;
184  i2cTransfer.buf[0].len = 2; /* Data is two bytes */
185  result = I2C_TransferInit(BUS_I2C, &i2cTransfer);
186 
187  /* Transmitting I2C data (busy-wait until transfer is complete) */
188  while (result == i2cTransferInProgress) result = I2C_Transfer(BUS_I2C);
189 
190  return (result);
191 }
#define SETTING_COMMAND
Definition: serlcd.c:106
#define BUS_I2C
Definition: pin_mapping.h:53
#define DISPLAY_ADDRESS
Definition: serlcd.c:102
int8_t initI2C(void)
I2C initialization (if not already initialized).
Definition: i2c.c:66
#define CLEAR_COMMAND
Definition: serlcd.c:109
unsigned char uint8_t
Typedef defining 8 bit unsigned char type. The developer should modify this to suit the platform bein...
Definition: vl53l1_types.h:98

◆ heartBeatLCD()

int8_t heartBeatLCD ( void  )

Update the heartbeat icon.

This method also initializes i2C if necessary.

Returns
  • 0 - Byte written correctly.
  • -1 - i2cTransferNack, NACK received during transfer.
  • -2 - i2cTransferBusErr, Bus error during transfer (misplaced START/STOP).
  • -3 - i2cTransferArbLost, Arbitration lost during transfer.
  • -4 - i2cTransferUsageFault, Usage fault.
  • -5 - i2cTransferSwFault, SW fault.
  • -6 - Coudldn't configure I2C.

Definition at line 361 of file serlcd.c.

362 {
363  /* Initialize I2C if not already the case */
364  if (initI2C() != 0) return (-6);
365 
366  /* Separate data in bytes */
367  uint8_t data_buf[3] = {254, LCD_SETDDRAMADDR | 19 }; /* 19th position on first row */
368 
369  /* Fill last location of data_buf according to heartBeat status */
370  if (heartBeat) data_buf[2] = '+';
371  else data_buf[2] = '*';
372  heartBeat = !heartBeat;
373 
374  /* Transfer structure */
375  I2C_TransferSeq_TypeDef i2cTransfer;
376  I2C_TransferReturn_TypeDef result;
377 
378  /* Initializing I2C transfer */
379  i2cTransfer.addr = DISPLAY_ADDRESS << 1; /* Left shift so we go to 8 bit notation instead of 7 */
380  i2cTransfer.flags = I2C_FLAG_WRITE; /* Data written from buf[0].data */
381  i2cTransfer.buf[0].data = data_buf;
382  i2cTransfer.buf[0].len = 3; /* Data is two bytes */
383  result = I2C_TransferInit(BUS_I2C, &i2cTransfer);
384 
385  /* Transmitting I2C data (busy-wait until transfer is complete) */
386  while (result == i2cTransferInProgress) result = I2C_Transfer(BUS_I2C);
387 
388  return (result);
389 }
#define LCD_SETDDRAMADDR
Definition: serlcd.c:124
#define BUS_I2C
Definition: pin_mapping.h:53
#define DISPLAY_ADDRESS
Definition: serlcd.c:102
bool heartBeat
Definition: serlcd.c:148
int8_t initI2C(void)
I2C initialization (if not already initialized).
Definition: i2c.c:66
unsigned char uint8_t
Typedef defining 8 bit unsigned char type. The developer should modify this to suit the platform bein...
Definition: vl53l1_types.h:98

◆ setCursorLCD()

int8_t setCursorLCD ( uint8_t  col,
uint8_t  row 
)

Set the cursor to a specific location on the LCD.

This method also initializes i2C if necessary.

Parameters
[in]colColumn (uint8_t, MAX = 20).
[in]rowRow (uint8_t, MAX = 4).
Returns
  • 0 - Byte written correctly.
  • -1 - i2cTransferNack, NACK received during transfer.
  • -2 - i2cTransferBusErr, Bus error during transfer (misplaced START/STOP).
  • -3 - i2cTransferArbLost, Arbitration lost during transfer.
  • -4 - i2cTransferUsageFault, Usage fault.
  • -5 - i2cTransferSwFault, SW fault.
  • -6 - Coudldn't configure I2C.

Definition at line 316 of file serlcd.c.

317 {
318  uint8_t row_offsets[] = {0x00, 0x40, 0x14, 0x54};
319 
320  /* Initialize I2C if not already the case */
321  if (initI2C() != 0) return (-6);
322 
323  /* Separate data in bytes */
324  uint8_t data_buf[2] = {254, LCD_SETDDRAMADDR | (col-1 + row_offsets[row-1])};
325 
326  /* Transfer structure */
327  I2C_TransferSeq_TypeDef i2cTransfer;
328  I2C_TransferReturn_TypeDef result;
329 
330  /* Initializing I2C transfer */
331  i2cTransfer.addr = DISPLAY_ADDRESS << 1; /* Left shift so we go to 8 bit notation instead of 7 */
332  i2cTransfer.flags = I2C_FLAG_WRITE; /* Data written from buf[0].data */
333  i2cTransfer.buf[0].data = data_buf;
334  i2cTransfer.buf[0].len = 2; /* Data is two bytes */
335  result = I2C_TransferInit(BUS_I2C, &i2cTransfer);
336 
337  /* Transmitting I2C data (busy-wait until transfer is complete) */
338  while (result == i2cTransferInProgress) result = I2C_Transfer(BUS_I2C);
339 
340  return (result);
341 }
#define LCD_SETDDRAMADDR
Definition: serlcd.c:124
#define BUS_I2C
Definition: pin_mapping.h:53
#define DISPLAY_ADDRESS
Definition: serlcd.c:102
int8_t initI2C(void)
I2C initialization (if not already initialized).
Definition: i2c.c:66
unsigned char uint8_t
Typedef defining 8 bit unsigned char type. The developer should modify this to suit the platform bein...
Definition: vl53l1_types.h:98

◆ writeCharLCD()

int8_t writeCharLCD ( uint8_t  data)

Write a character (one byte) to the LCD.

This method also initializes i2C if necessary.

Parameters
[in]dataThe data (uint8_t) to put on the I2C bus.
Returns
  • 0 - Byte written correctly.
  • -1 - i2cTransferNack, NACK received during transfer.
  • -2 - i2cTransferBusErr, Bus error during transfer (misplaced START/STOP).
  • -3 - i2cTransferArbLost, Arbitration lost during transfer.
  • -4 - i2cTransferUsageFault, Usage fault.
  • -5 - i2cTransferSwFault, SW fault.
  • -6 - Coudldn't configure I2C.

Definition at line 214 of file serlcd.c.

215 {
216  /* Initialize I2C if not already the case */
217  if (initI2C() != 0) return (-6);
218 
219  /* Separate data in bytes */
220  uint8_t data_buf[1] = {data};
221 
222  /* Transfer structure */
223  I2C_TransferSeq_TypeDef i2cTransfer;
224  I2C_TransferReturn_TypeDef result;
225 
226  /* Initializing I2C transfer */
227  i2cTransfer.addr = DISPLAY_ADDRESS << 1; /* Left shift so we go to 8 bit notation instead of 7 */
228  i2cTransfer.flags = I2C_FLAG_WRITE; /* Data written from buf[0].data */
229  i2cTransfer.buf[0].data = data_buf;
230  i2cTransfer.buf[0].len = 1; /* Data is one byte */
231  result = I2C_TransferInit(BUS_I2C, &i2cTransfer);
232 
233  /* Transmitting I2C data (busy-wait until transfer is complete) */
234  while (result == i2cTransferInProgress) result = I2C_Transfer(BUS_I2C);
235 
236  return (result);
237 }
MeasurementData_t data
Definition: main.c:86
#define BUS_I2C
Definition: pin_mapping.h:53
#define DISPLAY_ADDRESS
Definition: serlcd.c:102
int8_t initI2C(void)
I2C initialization (if not already initialized).
Definition: i2c.c:66
unsigned char uint8_t
Typedef defining 8 bit unsigned char type. The developer should modify this to suit the platform bein...
Definition: vl53l1_types.h:98

◆ writeStringLCD()

int8_t writeStringLCD ( char *  message)

Print a string (char array) to the LCD.

Note
If the input is not a string (ex.: "Hello world!") but a char array, the input message (array) needs to end with NULL ("\0")!

This method also initializes i2C if necessary.

Parameters
[in]messageThe string to print to the LCD.
Returns
  • 0 - Byte written correctly.
  • -1 - i2cTransferNack, NACK received during transfer.
  • -2 - i2cTransferBusErr, Bus error during transfer (misplaced START/STOP).
  • -3 - i2cTransferArbLost, Arbitration lost during transfer.
  • -4 - i2cTransferUsageFault, Usage fault.
  • -5 - i2cTransferSwFault, SW fault.
  • -6 - Coudldn't configure I2C.

Definition at line 264 of file serlcd.c.

265 {
266  /* Initialize I2C if not already the case */
267  if (initI2C() != 0) return (-6);
268 
269  /* Check string length */
270  uint8_t length = 0;
271 
272  /* Count up until we reach a NULL */
273  while (message[length] != '\0') length++;
274 
275  /* Transfer structure */
276  I2C_TransferSeq_TypeDef i2cTransfer;
277  I2C_TransferReturn_TypeDef result;
278 
279  /* Initializing I2C transfer */
280  i2cTransfer.addr = DISPLAY_ADDRESS << 1; /* Left shift so we go to 8 bit notation instead of 7 */
281  i2cTransfer.flags = I2C_FLAG_WRITE; /* Data written from buf[0].data */
282  i2cTransfer.buf[0].data = (unsigned char *)message;
283  i2cTransfer.buf[0].len = length; /* Data is one byte */
284  result = I2C_TransferInit(BUS_I2C, &i2cTransfer);
285 
286  /* Transmitting I2C data (busy-wait until transfer is complete) */
287  while (result == i2cTransferInProgress) result = I2C_Transfer(BUS_I2C);
288 
289  return (result);
290 }
#define BUS_I2C
Definition: pin_mapping.h:53
#define DISPLAY_ADDRESS
Definition: serlcd.c:102
int8_t initI2C(void)
I2C initialization (if not already initialized).
Definition: i2c.c:66
unsigned char uint8_t
Typedef defining 8 bit unsigned char type. The developer should modify this to suit the platform bein...
Definition: vl53l1_types.h:98