Ver código fonte

Make an LCD char print atomic

Solve issue with LCD concurrency.
DricomDragon 5 anos atrás
pai
commit
10a1e8e373
1 arquivos alterados com 9 adições e 1 exclusões
  1. 9 1
      prog/sources/lcd.cpp

+ 9 - 1
prog/sources/lcd.cpp

@@ -27,7 +27,11 @@ static const DigitalPort LCD_RS = DigitalPort::D18 ;
 
 static const DigitalPort LCD_E  = DigitalPort::D17 ;
 
-// UTILITY ROUTINES — ANY MODE                                                                                                  *
+// SEMAPHORE
+
+static Semaphore sem(1);
+
+// UTILITY ROUTINES — ANY MODE
 
 static void driveHighE (void) {
 	digitalWrite (LCD_E, true) ;
@@ -173,6 +177,8 @@ static void write8bitCommand (USER_MODE_ const uint8_t inCommand) {
 
 
 static void writeData (USER_MODE_ const uint8_t inData) {
+	sem.P(MODE);
+
 	waitDuring (MODE_ 1) ;
 	driveHighRS () ;
 	programLcd4BitDataBusOutput (inData >> 4) ;
@@ -184,6 +190,8 @@ static void writeData (USER_MODE_ const uint8_t inData) {
 	driveHighE () ;
 	waitDuring (MODE_ 1) ;
 	driveLowE () ;
+
+	sem.V(MODE);
 }
 
 // PRINT ROUTINES — USER MODE