forked from Neirth/FreeNOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented sleep() in libposix using a busy-loop (temporarily).
Added LCDBar device implementation for the GrovePi driver. Modified BroadcomI2C to use DEBUG() for several lines instead of NOTICE(). Added missing <String.h> in Device.h.
- Loading branch information
1 parent
0d99398
commit 639d8ce
Showing
7 changed files
with
263 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright (C) 2009 Niek Linnenbank | ||
* | ||
* 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. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <unistd.h> | ||
|
||
unsigned int sleep(unsigned int seconds) | ||
{ | ||
// TODO: kernel does not support sleep/wait scheduling yet. | ||
// Temporary busy-loop implementation, which is inaccurate. | ||
for (int i = 0; i < seconds * 1000000; i++); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
|
||
#include <Types.h> | ||
#include <errno.h> | ||
#include <String.h> | ||
|
||
/** | ||
* Abstract device class interface. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* Copyright (C) 2015 Niek Linnenbank | ||
* | ||
* 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. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <unistd.h> | ||
#include "LCDBar.h" | ||
|
||
LCDBar::LCDBar(I2C *i2c) | ||
{ | ||
m_i2c = i2c; | ||
m_identifier << "groveLCD"; | ||
} | ||
|
||
Error LCDBar::initialize() | ||
{ | ||
return ESUCCESS; | ||
} | ||
|
||
Error LCDBar::write(s8 *buffer, Size size, Size offset) | ||
{ | ||
setRGB(0, 255, 0); | ||
setText((const char *) buffer, size); | ||
return size; | ||
} | ||
|
||
void LCDBar::textCommand(LCDBar::Command cmd) | ||
{ | ||
u8 command[2]; | ||
|
||
command[0] = 0x80; | ||
command[1] = cmd; | ||
|
||
m_i2c->setAddress(TextAddr); | ||
m_i2c->write(command, sizeof(command)); | ||
} | ||
|
||
void LCDBar::setText(const char *text, Size max) | ||
{ | ||
textCommand(ClearDisplay); | ||
sleep(1); | ||
|
||
textCommand(DisplayOn | NoCursor); | ||
textCommand(DoubleLine); | ||
sleep(1); | ||
|
||
for (uint line = 0; line < 2; line++) | ||
{ | ||
for (uint i = 0; i < 16; i++) | ||
{ | ||
if (i + (line * 16) >= max) | ||
return; | ||
|
||
char v = text[i + (line * 16)]; | ||
|
||
if (!v) | ||
return; | ||
else if (v == '\n') | ||
{ | ||
textCommand(Newline); | ||
break; | ||
} | ||
else | ||
{ | ||
u8 command[2]; | ||
command[0] = 0x40; | ||
command[1] = v; | ||
m_i2c->write(command, sizeof(command)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
void LCDBar::setRGB(uint r, uint g, uint b) | ||
{ | ||
u8 command[2]; | ||
command[0] = 0; | ||
command[1] = 0; | ||
m_i2c->setAddress(0x62); | ||
m_i2c->write(command, sizeof(command)); // 0,0 | ||
|
||
command[0] = 1; | ||
m_i2c->write(command, sizeof(command)); // 1,0 | ||
|
||
command[0] = 0x8; | ||
command[1] = 0xaa; | ||
m_i2c->write(command, sizeof(command)); // 0x08,0xaa | ||
|
||
command[0] = 4; | ||
command[1] = r; | ||
m_i2c->write(command, sizeof(command)); // 4,r | ||
|
||
command[0] = 3; | ||
command[1] = g; | ||
m_i2c->write(command, sizeof(command)); // 3,g | ||
|
||
command[0] = 2; | ||
command[1] = b; | ||
m_i2c->write(command, sizeof(command)); // 2,b | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Copyright (C) 2015 Niek Linnenbank | ||
* | ||
* 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. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef __SERVER_I2C_GROVEPI_LCDBAR_H | ||
#define __SERVER_I2C_GROVEPI_LCDBAR_H | ||
|
||
/** | ||
* @defgroup groveDigi GrovePi LCD Bar | ||
* @{ | ||
*/ | ||
|
||
#include <Macros.h> | ||
#include <Types.h> | ||
#include <Device.h> | ||
#include <I2C.h> | ||
|
||
/** | ||
* @brief GrovePi LCD Bar | ||
* | ||
* @see https://github.com/DexterInd/GrovePi/blob/master/Firmware/Source/v1.2/grove_pi_v1_2_5/README.md | ||
*/ | ||
class LCDBar : public Device | ||
{ | ||
private: | ||
|
||
static const uint RGBAddr = 0x62; | ||
static const uint TextAddr = 0x3e; | ||
|
||
/** | ||
* LCDBar commands. | ||
*/ | ||
enum Command | ||
{ | ||
ClearDisplay = 0x01, | ||
NoCursor = 0x04, | ||
DisplayOn = 0x08, | ||
DoubleLine = 0x28, | ||
Newline = 0xc0, | ||
WriteChar = 0x40 | ||
}; | ||
|
||
public: | ||
|
||
/** | ||
* @brief Constructor function. | ||
*/ | ||
LCDBar(I2C *i2c); | ||
|
||
/** | ||
* @brief Initializes the class. | ||
* | ||
* @return Error status code. | ||
*/ | ||
virtual Error initialize(); | ||
|
||
/** | ||
* @brief Set LCD Bar text. | ||
* | ||
* @param buffer Buffer to save the read bytes. | ||
* @param size Number of bytes to read. | ||
* @param offset Offset in the file to read. | ||
* @return Number of bytes on success and ZERO on failure. | ||
*/ | ||
virtual Error write(s8 *buffer, Size size, Size offset); | ||
|
||
private: | ||
|
||
/** | ||
* Set LCD color. | ||
*/ | ||
void setRGB(uint r, uint g, uint b); | ||
|
||
/** | ||
* Set LCD text. | ||
*/ | ||
void setText(const char *text, Size max); | ||
|
||
/** | ||
* Send I2C text command. | ||
*/ | ||
void textCommand(Command cmd); | ||
|
||
/** I2C controller */ | ||
I2C *m_i2c; | ||
}; | ||
|
||
/** | ||
* @} | ||
*/ | ||
|
||
#endif /* __TIME_TIME_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters