Merge branch 'ykiveish-master'

This commit is contained in:
Brendan Le Foll 2014-06-02 11:47:56 +01:00
commit 83c29cc330
35 changed files with 1722 additions and 156 deletions

View File

@ -0,0 +1,42 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <iostream>
#include "tm1637.h"
int
main(int argc, char **argv)
{
uint8_t data[] = { 0xaa, 0xff, 0xff, 0xff };
upm::TM1637 *display = new upm::TM1637(8, 9); // di - 8, dcki - 9
display->write ("1981");
std::cout << "exiting application" << std::endl;
delete display;
return 0;
}

View File

@ -2,15 +2,28 @@ add_executable (compass compass.cxx)
add_executable (groveled groveled.cxx) add_executable (groveled groveled.cxx)
add_executable (grovetemp grovetemp.cxx) add_executable (grovetemp grovetemp.cxx)
add_executable (lcm-lcd lcm-lcd.cxx) add_executable (lcm-lcd lcm-lcd.cxx)
add_executable (rgb-lcd rgb-lcd.cxx)
add_executable (buzzer-sound buzzer-sound.cxx) add_executable (buzzer-sound buzzer-sound.cxx)
add_executable (led-bar led-bar.cxx)
add_executable (seg-lcd 4digitdisplay.cxx)
add_executable (nrf_transmitter nrf_transmitter.cxx)
add_executable (nrf_receiver nrf_receiver.cxx)
include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l) include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
include_directories (${PROJECT_SOURCE_DIR}/src/grove) include_directories (${PROJECT_SOURCE_DIR}/src/grove)
include_directories (${PROJECT_SOURCE_DIR}/src/lcm1602) include_directories (${PROJECT_SOURCE_DIR}/src/lcd)
include_directories (${PROJECT_SOURCE_DIR}/src/buzzer) include_directories (${PROJECT_SOURCE_DIR}/src/buzzer)
include_directories (${PROJECT_SOURCE_DIR}/src/ledbar)
include_directories (${PROJECT_SOURCE_DIR}/src/4digitdisplay)
include_directories (${PROJECT_SOURCE_DIR}/src/nrf24l01)
target_link_libraries (compass hmc5883l ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries (compass hmc5883l ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (groveled grove ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries (groveled grove ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (grovetemp grove ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries (grovetemp grove ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (lcm-lcd lcm1602 ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries (lcm-lcd i2clcd ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (rgb-lcd i2clcd ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (buzzer-sound buzzer ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries (buzzer-sound buzzer ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (led-bar ledbar ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (seg-lcd 4digitdisplay ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (nrf_transmitter nrf24l01 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (nrf_receiver nrf24l01 ${CMAKE_THREAD_LIBS_INIT})

View File

@ -28,13 +28,13 @@ int
main(int argc, char **argv) main(int argc, char **argv)
{ {
upm::Lcm1602* lcd = new upm::Lcm1602(0, 0x27); upm::Lcm1602* lcd = new upm::Lcm1602(0, 0x27);
lcd->cursor(0,0); lcd->setCursor(0,0);
lcd->write("Hello World"); lcd->write("Hello World");
lcd->cursor(1,2); lcd->setCursor(1,2);
lcd->write("Hello World"); lcd->write("Hello World");
lcd->cursor(2,4); lcd->setCursor(2,4);
lcd->write("Hello World"); lcd->write("Hello World");
lcd->cursor(3,6); lcd->setCursor(3,6);
lcd->write("Hello World"); lcd->write("Hello World");
lcd->close(); lcd->close();
} }

61
examples/led-bar.cxx Normal file
View File

@ -0,0 +1,61 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <unistd.h>
#include <iostream>
#include "my9221.h"
#include <signal.h>
int running = 0;
void
sig_handler(int signo)
{
printf("got signal\n");
if (signo == SIGINT) {
printf("exiting application\n");
running = 1;
}
}
int
main(int argc, char **argv)
{
upm::MY9221 *bar = new upm::MY9221(8, 9);
signal(SIGINT, sig_handler);
while (!running) {
for (int idx = 1; idx < 11; idx++) {
bar->setBarLevel (idx);
usleep(1000);
}
}
std::cout << "exiting application" << std::endl;
delete bar;
return 0;
}

69
examples/nrf_receiver.cxx Normal file
View File

@ -0,0 +1,69 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <string.h>
#include <unistd.h>
#include <iostream>
#include "nrf24l01.h"
#include <signal.h>
int running = 0;
upm::NRF24l01 *comm = NULL;
void
sig_handler(int signo)
{
printf("got signal\n");
if (signo == SIGINT) {
printf("exiting application\n");
running = 1;
}
}
void nrf_handler () {
std::cout << "devi1 :: " << *((uint32_t *)&(comm->m_rxBuffer[0])) << std::endl;
}
int
main(int argc, char **argv)
{
comm = new upm::NRF24l01(7);
comm->nrfSetRXaddr ((uint8_t *) "devi1");
comm->nrfSetTXaddr ((uint8_t *) "devi2");
comm->nrfSetPayload (MAX_BUFFER);
comm->nrfConfigModule ();
comm->dataRecievedHandler = nrf_handler;
signal(SIGINT, sig_handler);
while (!running) {
comm->nrfListenForChannel ();
}
std::cout << "exiting application" << std::endl;
delete comm;
return 0;
}

View File

@ -0,0 +1,73 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <string.h>
#include <unistd.h>
#include <iostream>
#include "nrf24l01.h"
#include <signal.h>
int running = 0;
upm::NRF24l01 *comm = NULL;
void
sig_handler(int signo)
{
printf("got signal\n");
if (signo == SIGINT) {
printf("exiting application\n");
running = 1;
}
}
void nrf_handler () {
}
int
main(int argc, char **argv)
{
uint32_t dummyData = 0;
comm = new upm::NRF24l01(7);
comm->nrfSetRXaddr ((uint8_t *) "devi2");
comm->nrfSetTXaddr ((uint8_t *) "devi1");
comm->nrfSetPayload (MAX_BUFFER);
comm->nrfConfigModule ();
comm->dataRecievedHandler = nrf_handler;
signal(SIGINT, sig_handler);
while (!running) {
memcpy (comm->m_txBuffer, &dummyData, sizeof (dummyData));
comm->nrfSend ();
std::cout << "devi2 :: sending data ...." << dummyData << std::endl;
usleep (3000000);
dummyData += 3000;
}
std::cout << "exiting application" << std::endl;
delete comm;
return 0;
}

37
examples/rgb-lcd.cxx Normal file
View File

@ -0,0 +1,37 @@
/*
* Author: Yevgeniy Kiveish <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "jhd1313m1.h"
int
main(int argc, char **argv)
{
// 0x62 RGB_ADDRESS, 0x3E LCD_ADDRESS
upm::Jhd1313m1 *lcd = new upm::Jhd1313m1(0, 0x3E, 0x62);
lcd->setCursor(0,0);
lcd->write("Hello World");
lcd->setCursor(1,2);
lcd->write("Hello World");
lcd->close();
}

View File

@ -0,0 +1,4 @@
set (libname "4digitdisplay")
add_library (4digitdisplay SHARED tm1637.cxx)
include_directories (${MAA_INCLUDE_DIR})
target_link_libraries (4digitdisplay ${MAA_LIBRARIES})

View File

@ -0,0 +1,7 @@
%module jsupm_tm1637
%{
#include "tm1637.h"
%}
%include "tm1637.h"

View File

@ -0,0 +1,8 @@
%module pyupm_tm1637
%feature("autodoc", "3");
%include "tm1637.h"
%{
#include "tm1637.h"
%}

View File

@ -0,0 +1,190 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <iostream>
#include <unistd.h>
#include "tm1637.h"
using namespace upm;
const uint8_t digitToSegment[] = {
// XGFEDCBA
0b00111111, // 0
0b00000110, // 1
0b01011011, // 2
0b01001111, // 3
0b01100110, // 4
0b01101101, // 5
0b01111101, // 6
0b00000111, // 7
0b01111111, // 8
0b01101111, // 9
0b01110111, // A
0b01111100, // B
0b00111001, // C
0b01000111, // D
0b01111001, // E
0b01110001 // F
};
TM1637::TM1637 (uint8_t di, uint8_t dcki) {
maa_result_t error = MAA_SUCCESS;
maa_init();
// init clock context
m_clkPinCtx = maa_gpio_init(dcki);
if (m_clkPinCtx == NULL) {
fprintf(stderr, "Are you sure that pin%d you requested is valid on your platform?", dcki);
exit(1);
}
// init data context
m_dataPinCtx = maa_gpio_init(di);
if (m_dataPinCtx == NULL) {
fprintf(stderr, "Are you sure that pin%d you requested is valid on your platform?", di);
exit(1);
}
// set direction (out)
error = maa_gpio_dir(m_clkPinCtx, MAA_GPIO_IN);
if (error != MAA_SUCCESS) {
maa_result_print(error);
}
// set direction (out)
error = maa_gpio_dir(m_dataPinCtx, MAA_GPIO_IN);
if (error != MAA_SUCCESS) {
maa_result_print(error);
}
error = maa_gpio_write (m_dataPinCtx, LOW);
error = maa_gpio_write (m_clkPinCtx, LOW);
}
TM1637::~TM1637() {
maa_result_t error = MAA_SUCCESS;
error = maa_gpio_close (m_dataPinCtx);
if (error != MAA_SUCCESS) {
maa_result_print(error);
}
error = maa_gpio_close (m_clkPinCtx);
if (error != MAA_SUCCESS) {
maa_result_print(error);
}
}
maa_result_t
TM1637::setBrightness (uint8_t level) {
m_brightness = level;
}
maa_result_t
TM1637::setSegments (const uint8_t segments[], uint8_t length, uint8_t pos) {
start();
writeByte(TM1637_I2C_COMM1);
stop();
start();
writeByte(TM1637_I2C_COMM2 + (pos & 0x03));
for (uint8_t idx = 0; idx < length; idx++) {
writeByte(segments[idx]);
}
stop();
start();
writeByte(TM1637_I2C_COMM3 + (m_brightness & 0x0f));
stop();
}
maa_result_t
TM1637::write (std::string msg) {
char leter = '\0';
uint8_t data[] = { 0x0, 0x0, 0x0, 0x0 };
for (uint8_t idx = 0; idx < msg.length(); idx++) {
leter = msg[idx];
if (idx < 4) {
data[idx] = digitToSegment[strtol(&leter, NULL, 16)];
}
}
setBrightness (0x0f);
setSegments(data);
}
maa_result_t
TM1637::pinMode (maa_gpio_context ctx, gpio_dir_t mode) {
maa_result_t error = MAA_SUCCESS;
error = maa_gpio_dir(ctx, mode);
if (error != MAA_SUCCESS) {
maa_result_print(error);
}
}
maa_result_t
TM1637::start() {
pinMode (m_dataPinCtx, MAA_GPIO_OUT);
usleep(PULSE_LENGTH);
}
maa_result_t
TM1637::stop() {
pinMode (m_dataPinCtx, MAA_GPIO_OUT);
usleep(PULSE_LENGTH);
pinMode (m_clkPinCtx, MAA_GPIO_IN);
usleep(PULSE_LENGTH);
pinMode (m_dataPinCtx, MAA_GPIO_IN);
usleep(PULSE_LENGTH);
}
maa_result_t
TM1637::writeByte(uint8_t value) {
for (uint8_t idx = 0; idx < 8; idx++) {
pinMode(m_clkPinCtx, MAA_GPIO_OUT);
usleep(PULSE_LENGTH);
if (value & 0x01) {
pinMode(m_dataPinCtx, MAA_GPIO_IN);
} else {
pinMode(m_dataPinCtx, MAA_GPIO_OUT);
}
usleep(PULSE_LENGTH);
pinMode(m_clkPinCtx, MAA_GPIO_IN);
usleep(PULSE_LENGTH);
value = value >> 1;
}
pinMode(m_clkPinCtx, MAA_GPIO_OUT);
pinMode(m_dataPinCtx, MAA_GPIO_IN);
usleep(PULSE_LENGTH);
pinMode(m_clkPinCtx, MAA_GPIO_IN);
usleep(PULSE_LENGTH);
uint8_t ack = maa_gpio_read (m_dataPinCtx);
if (ack == 0) {
pinMode(m_dataPinCtx, MAA_GPIO_OUT);
} usleep(PULSE_LENGTH);
pinMode(m_clkPinCtx, MAA_GPIO_OUT);
usleep(50);
}

View File

@ -0,0 +1,82 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <string>
#include <maa/aio.h>
#include <maa/gpio.h>
//
// A
// ---
// F | | B
// -G-
// E | | C
// ---
// D
#define SEG_A 0b00000001
#define SEG_B 0b00000010
#define SEG_C 0b00000100
#define SEG_D 0b00001000
#define SEG_E 0b00010000
#define SEG_F 0b00100000
#define SEG_G 0b01000000
#define TM1637_I2C_COMM1 0x40
#define TM1637_I2C_COMM2 0xC0
#define TM1637_I2C_COMM3 0x80
#define PULSE_LENGTH 50
#define HIGH 1
#define LOW 0
namespace upm {
class TM1637 {
public:
TM1637 (uint8_t di, uint8_t dcki);
~TM1637 ();
maa_result_t setBrightness (uint8_t level);
maa_result_t setSegments (const uint8_t segments[], uint8_t length = 4, uint8_t pos = 0);
maa_result_t write (std::string msg);
std::string name()
{
return m_name;
}
private:
maa_result_t start();
maa_result_t stop();
maa_result_t writeByte (uint8_t value);
maa_result_t pinMode (maa_gpio_context ctx, gpio_dir_t mode);
std::string m_name;
maa_gpio_context m_clkPinCtx;
maa_gpio_context m_dataPinCtx;
uint8_t m_brightness;
};
}

View File

@ -1,4 +1,7 @@
add_subdirectory (hmc5883l) add_subdirectory (hmc5883l)
add_subdirectory (grove) add_subdirectory (grove)
add_subdirectory (lcm1602) add_subdirectory (lcd)
add_subdirectory (buzzer) add_subdirectory (buzzer)
add_subdirectory (ledbar)
add_subdirectory (4digitdisplay)
add_subdirectory (nrf24l01)

4
src/lcd/CMakeLists.txt Normal file
View File

@ -0,0 +1,4 @@
set (libname "i2clcd")
add_library (i2clcd SHARED iiclcd.cxx lcm1602.cxx jhd1313m1.cxx)
include_directories (${MAA_INCLUDE_DIR})
target_link_libraries (i2clcd ${MAA_LIBRARIES})

53
src/lcd/iiclcd.cxx Normal file
View File

@ -0,0 +1,53 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <iostream>
#include <unistd.h>
#include "iiclcd.h"
using namespace upm;
IICLcd::IICLcd (int bus, int lcdAddress) {
m_lcd_control_address = lcdAddress;
m_bus = bus;
m_i2c_lcd_control = maa_i2c_init(m_bus);
maa_result_t ret = maa_i2c_address(m_i2c_lcd_control, m_lcd_control_address);
if (ret != MAA_SUCCESS) {
fprintf(stderr, "Messed up i2c bus\n");
}
}
maa_result_t
IICLcd::write (int row, int column, std::string msg) {
setCursor (row, column);
write (msg);
}
maa_result_t
IICLcd::close() {
return maa_i2c_stop(m_i2c_lcd_control);
}

90
src/lcd/iiclcd.h Normal file
View File

@ -0,0 +1,90 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <string>
#include <maa/i2c.h>
namespace upm {
// commands
#define LCD_CLEARDISPLAY 0x01
#define LCD_RETURNHOME 0x02
#define LCD_ENTRYMODESET 0x04
#define LCD_DISPLAYCONTROL 0x08
#define LCD_CURSORSHIFT 0x10
#define LCD_FUNCTIONSET 0x20
#define LCD_SETCGRAMADDR 0x40
#define LCD_SETDDRAMADDR 0x80
#define LCD_BACKLIGHT 0x08
#define LCD_NOBACKLIGHT 0x00
// flags for display entry mode
#define LCD_ENTRYRIGHT 0x00
#define LCD_ENTRYLEFT 0x02
#define LCD_ENTRYSHIFTINCREMENT 0x01
#define LCD_ENTRYSHIFTDECREMENT 0x00
// flags for display on/off control
#define LCD_DISPLAYON 0x04
#define LCD_DISPLAYOFF 0x00
#define LCD_CURSORON 0x02
#define LCD_CURSOROFF 0x00
#define LCD_BLINKON 0x01
#define LCD_BLINKOFF 0x00
// flags for function set
#define LCD_8BITMODE 0x10
#define LCD_4BITMODE 0x00
#define LCD_2LINE 0x08
#define LCD_1LINE 0x00
#define LCD_5x10DOTS 0x04
#define LCD_5x8DOTS 0x00
#define LCD_EN 0x04 // Enable bit
#define LCD_RW 0x02 // Read/Write bit
#define LCD_RS 0x01 // Register select bit
class IICLcd {
public:
IICLcd (int bus, int lcdAddress);
virtual maa_result_t write (std::string msg) = 0;
maa_result_t write (int x, int y, std::string msg);
virtual maa_result_t setCursor (int row, int column) = 0;
virtual maa_result_t clear () = 0;
virtual maa_result_t home () = 0;
maa_result_t close();
std::string name()
{
return m_name;
}
protected:
std::string m_name;
int m_lcd_control_address;
int m_bus;
maa_i2c_context m_i2c_lcd_control;
};
}

140
src/lcd/jhd1313m1.cxx Normal file
View File

@ -0,0 +1,140 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <iostream>
#include <unistd.h>
#include "jhd1313m1.h"
using namespace upm;
Jhd1313m1::Jhd1313m1 (int bus, int lcdAddress, int rgbAddress) : IICLcd(bus, lcdAddress) {
maa_result_t error = MAA_SUCCESS;
m_rgb_address = rgbAddress;
m_i2c_lcd_rgb = maa_i2c_init(m_bus);
maa_result_t ret = maa_i2c_address(m_i2c_lcd_rgb, m_rgb_address);
if (ret != MAA_SUCCESS) {
fprintf(stderr, "Messed up i2c bus\n");
}
usleep(50000);
cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
usleep(4500);
cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
usleep(4500);
cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
usleep(4500);
cmd (m_i2c_lcd_control, LCD_FUNCTIONSET | LCD_2LINE);
cmd (m_i2c_lcd_control, LCD_DISPLAYCONTROL | LCD_DISPLAYON);
clear ();
usleep(4500);
cmd (m_i2c_lcd_control, LCD_ENTRYMODESET |
LCD_ENTRYLEFT |
LCD_ENTRYSHIFTDECREMENT);
setReg (m_i2c_lcd_rgb, m_rgb_address, 0, 0);
setReg (m_i2c_lcd_rgb, m_rgb_address, 1, 0);
setReg (m_i2c_lcd_rgb, m_rgb_address, 0x08, 0xAA);
setReg (m_i2c_lcd_rgb, m_rgb_address, 0x04, 255);
setReg (m_i2c_lcd_rgb, m_rgb_address, 0x03, 255);
setReg (m_i2c_lcd_rgb, m_rgb_address, 0x02, 255);
}
Jhd1313m1::~Jhd1313m1() {
}
/*
* **************
* virtual area
* **************
*/
maa_result_t
Jhd1313m1::write (std::string msg) {
maa_result_t error = MAA_SUCCESS;
uint8_t data[2] = {0x40, 0};
for (std::string::size_type i = 0; i < msg.size(); ++i) {
data[1] = msg[i];
error = maa_i2c_address (m_i2c_lcd_control, m_lcd_control_address);
error = maa_i2c_write (m_i2c_lcd_control, data, 2);
}
return error;
}
maa_result_t
Jhd1313m1::setCursor (int row, int column) {
maa_result_t error = MAA_SUCCESS;
int row_addr[] = { 0x80, 0xc0, 0x14, 0x54};
uint8_t offset = ((column % 16) + row_addr[row]);
uint8_t data[2] = { 0x80, offset };
error = maa_i2c_address (m_i2c_lcd_control, m_lcd_control_address);
error = maa_i2c_write (m_i2c_lcd_control, data, 2);
return error;
}
maa_result_t
Jhd1313m1::clear () {
return cmd (m_i2c_lcd_control, LCD_CLEARDISPLAY);
}
maa_result_t
Jhd1313m1::home () {
return cmd (m_i2c_lcd_control, LCD_RETURNHOME);
}
/*
* **************
* private area
* **************
*/
maa_result_t
Jhd1313m1::setReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t value) {
maa_result_t error = MAA_SUCCESS;
uint8_t data[2] = { addr, value };
error = maa_i2c_address (ctx, deviceAdress);
error = maa_i2c_write (ctx, data, 2);
return error;
}
maa_result_t
Jhd1313m1::cmd (maa_i2c_context ctx, uint8_t value) {
maa_result_t error = MAA_SUCCESS;
uint8_t data[2] = { 0x80, value };
error = maa_i2c_address (ctx, m_lcd_control_address);
error = maa_i2c_write (ctx, data, 2);
return error;
}

48
src/lcd/jhd1313m1.h Normal file
View File

@ -0,0 +1,48 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <string>
#include "iiclcd.h"
namespace upm {
class Jhd1313m1 : public IICLcd {
public:
Jhd1313m1 (int bus, int lcdAddress, int rgbAddress);
~Jhd1313m1 ();
maa_result_t write (std::string msg);
maa_result_t setCursor (int row, int column);
maa_result_t clear ();
maa_result_t home ();
private:
maa_result_t cmd (maa_i2c_context ctx, uint8_t value);
maa_result_t setReg (maa_i2c_context ctx, int deviceAdress, int addr, uint8_t data);
int m_rgb_address;
maa_i2c_context m_i2c_lcd_rgb;
};
}

View File

@ -0,0 +1,7 @@
%module jsupm_jhd1313m1
%{
#include "jhd1313m1.h"
%}
%include "jhd1313m1.h"

View File

@ -30,56 +30,13 @@
#include "lcm1602.h" #include "lcm1602.h"
#define LCD_CLEARDISPLAY 0x01
#define LCD_RETURNHOME 0x02
#define LCD_ENTRYMODESET 0x04
#define LCD_DISPLAYCONTROL 0x08
#define LCD_CURSORSHIFT 0x10
#define LCD_FUNCTIONSET 0x20
#define LCD_SETCGRAMADDR 0x40
#define LCD_SETDDRAMADDR 0x80
#define LCD_BACKLIGHT 0x08
#define LCD_NOBACKLIGHT 0x00
#define LCD_ENTRYRIGHT 0x00
#define LCD_ENTRYLEFT 0x02
#define LCD_ENTRYSHIFTINCREMENT 0x01
#define LCD_ENTRYSHIFTDECREMENT 0x00
#define LCD_DISPLAYON 0x04
#define LCD_DISPLAYOFF 0x00
#define LCD_CURSORON 0x02
#define LCD_CURSOROFF 0x00
#define LCD_BLINKON 0x01
#define LCD_BLINKOFF 0x00
#define LCD_8BITMODE 0x10
#define LCD_4BITMODE 0x00
#define LCD_2LINE 0x08
#define LCD_1LINE 0x00
#define LCD_5x10DOTS 0x04
#define LCD_5x8DOTS 0x00
#define LCD_EN 0x04 // Enable bit
#define LCD_RW 0x02 // Read/Write bit
#define LCD_RS 0x01 // Register select bit
using namespace upm; using namespace upm;
Lcm1602::Lcm1602(int bus_in, int addr_in) Lcm1602::Lcm1602(int bus_in, int addr_in) : IICLcd (bus_in, addr_in) {
{ maa_result_t error = MAA_SUCCESS;
m_address = addr_in;
m_bus = bus_in;
m_i2c = maa_i2c_init(m_bus); usleep(50000);
expandWrite(LCD_BACKLIGHT);
maa_result_t ret = maa_i2c_address(m_i2c, m_address);
if (ret != MAA_SUCCESS) {
fprintf(stderr, "Messed up i2c bus\n");
}
usleep(50000);
expandWrite(LCD_BACKLIGHT);
usleep(100000); usleep(100000);
write4bits(0x03 << 4); write4bits(0x03 << 4);
@ -103,47 +60,52 @@ Lcm1602::Lcm1602(int bus_in, int addr_in)
home(); home();
} }
int Lcm1602::~Lcm1602 () {
Lcm1602::clear()
{
return send(LCD_CLEARDISPLAY, 0);
}
int
Lcm1602::home()
{
return send(LCD_RETURNHOME, 0);
}
int
Lcm1602::cursor(int row, int column)
{
if (row > 3)
return 99;
int row_addr[] = { 0x80, 0xc0, 0x14, 0x54};
return send(LCD_SETDDRAMADDR | ((column % 16) + row_addr[row]),0);
} }
/*
* **************
* virtual area
* **************
*/
maa_result_t maa_result_t
Lcm1602::write(std::string msg) Lcm1602::write (std::string msg) {
{ maa_result_t error = MAA_SUCCESS;
maa_result_t ret = MAA_SUCCESS; for (std::string::size_type i = 0; i < msg.size(); ++i) {
for(std::string::size_type i = 0; i < msg.size(); ++i) { error = send (msg[i], LCD_RS);
ret = send(msg[i], LCD_RS);
} }
return ret; return error;
} }
maa_result_t maa_result_t
Lcm1602::close() Lcm1602::setCursor (int row, int column) {
{ maa_result_t error = MAA_SUCCESS;
return maa_i2c_stop(m_i2c);
int row_addr[] = { 0x80, 0xc0, 0x14, 0x54};
uint8_t offset = ((column % 16) + row_addr[row]);
return send (LCD_SETDDRAMADDR | offset, 0);
} }
maa_result_t maa_result_t
Lcm1602::send(uint8_t value, int mode) Lcm1602::clear () {
{ return send(LCD_CLEARDISPLAY, 0);
maa_result_t ret = MAA_SUCCESS; }
maa_result_t
Lcm1602::home () {
return send(LCD_RETURNHOME, 0);
}
/*
* **************
* private area
* **************
*/
maa_result_t
Lcm1602::send (uint8_t value, int mode) {
maa_result_t ret = MAA_SUCCESS;
uint8_t h = value & 0xf0; uint8_t h = value & 0xf0;
uint8_t l = (value << 4) & 0xf0; uint8_t l = (value << 4) & 0xf0;
ret = write4bits(h | mode); ret = write4bits(h | mode);
@ -164,7 +126,7 @@ maa_result_t
Lcm1602::expandWrite(uint8_t value) Lcm1602::expandWrite(uint8_t value)
{ {
uint8_t buffer = value | LCD_BACKLIGHT; uint8_t buffer = value | LCD_BACKLIGHT;
return maa_i2c_write_byte(m_i2c, buffer); return maa_i2c_write_byte(m_i2c_lcd_control, buffer);
} }
maa_result_t maa_result_t

View File

@ -28,37 +28,28 @@
#pragma once #pragma once
#include <string> #include <string>
#include <maa/i2c.h> #include "iiclcd.h"
namespace upm { namespace upm {
class Lcm1602 { class Lcm1602 : public IICLcd {
public: public:
/** LCM1602 Constructor. /** LCM1602 Constructor.
* Calls MAA initialisation functions. * Calls MAA initialisation functions.
* @param bus i2c bus to use * @param bus i2c bus to use
* @param address the slave address the lcd is registered on. * @param address the slave address the lcd is registered on.
*/ */
Lcm1602(int bus, int address); Lcm1602(int bus, int address);
~Lcm1602();
// Clear the screen maa_result_t write (std::string msg);
int clear(); maa_result_t setCursor (int row, int column);
// Set the cursor to home maa_result_t clear ();
int home(); maa_result_t home ();
// change cursor to row,column.
int cursor(int row, int column);
//write a string at the position
maa_result_t write(std::string msg);
maa_result_t close();
private:
int m_address;
int m_bus;
maa_result_t send(uint8_t value, int mode);
maa_result_t write4bits(uint8_t value);
maa_result_t expandWrite(uint8_t value);
maa_result_t pulseEnable(uint8_t value);
maa_i2c_context m_i2c;
};
private :
maa_result_t send (uint8_t value, int mode);
maa_result_t write4bits(uint8_t value);
maa_result_t expandWrite(uint8_t value);
maa_result_t pulseEnable(uint8_t value);
};
} }

View File

@ -0,0 +1,8 @@
%module pyupm_jhd1313m1
%feature("autodoc", "3");
%include "jhd1313m1.h"
%{
#include "jhd1313m1.h"
%}

View File

@ -1,39 +0,0 @@
set (libname "lcm1602")
add_library (lcm1602 SHARED lcm1602.cxx)
include_directories (${MAA_INCLUDE_DIR})
target_link_libraries (lcm1602 ${MAA_LIBRARIES})
if (SWIG_FOUND)
find_package (PythonLibs)
include_directories (
${PYTHON_INCLUDE_PATH}
${PYTHON_INCLUDE_DIRS}
${MAA_INCLUDE_DIR}
.
)
set_source_files_properties (pyupm_lcm1602.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties (jsupm_lcm1602.i PROPERTIES CPLUSPLUS ON)
set_source_files_properties (jsupm_lcm1602.i PROPERTIES SWIG_FLAGS "-node")
swig_add_module (pyupm_lcm1602 python pyupm_lcm1602.i lcm1602.cxx)
# swig_add_module (jsupm_lcm1602 javascript jsupm_lcm1602.i lcm1602.cxx)
swig_link_libraries (pyupm_lcm1602 ${PYTHON_LIBRARIES} ${MAA_LIBRARIES})
# swig_link_libraries (jsupm_lcm1602 ${MAA_LIBRARIES})
if (DOXYGEN_FOUND)
set (CMAKE_SWIG_FLAGS -DDOXYGEN=${DOXYGEN_FOUND})
add_custom_command (OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/../doxy2swig.py -n
${CMAKE_BINARY_DIR}/xml/${libname}_8h.xml
${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i
DEPENDS ${CMAKE_BINARY_DIR}/xml/${libname}_8h.xml
)
add_custom_target (${libname}doc_i DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${libname}_doc.i)
add_dependencies (${libname}doc_i doc)
add_dependencies (${SWIG_MODULE_pyupm_lcm1602_REAL_NAME} ${libname}doc_i)
endif ()
endif ()

View File

@ -0,0 +1,4 @@
set (libname "ledbar")
add_library (ledbar SHARED my9221.cxx)
include_directories (${MAA_INCLUDE_DIR})
target_link_libraries (ledbar ${MAA_LIBRARIES})

View File

@ -0,0 +1,7 @@
%module jsupm_my9221
%{
#include "my9221.h"
%}
%include "my9221.h"

118
src/ledbar/my9221.cxx Normal file
View File

@ -0,0 +1,118 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <iostream>
#include <unistd.h>
#include "my9221.h"
using namespace upm;
MY9221::MY9221 (uint8_t di, uint8_t dcki) {
maa_result_t error = MAA_SUCCESS;
maa_init();
// init clock context
m_clkPinCtx = maa_gpio_init(dcki);
if (m_clkPinCtx == NULL) {
fprintf(stderr, "Are you sure that pin%d you requested is valid on your platform?", dcki);
exit(1);
}
// init data context
m_dataPinCtx = maa_gpio_init(di);
if (m_dataPinCtx == NULL) {
fprintf(stderr, "Are you sure that pin%d you requested is valid on your platform?", di);
exit(1);
}
// set direction (out)
error = maa_gpio_dir(m_clkPinCtx, MAA_GPIO_OUT);
if (error != MAA_SUCCESS) {
maa_result_print(error);
}
// set direction (out)
error = maa_gpio_dir(m_dataPinCtx, MAA_GPIO_OUT);
if (error != MAA_SUCCESS) {
maa_result_print(error);
}
}
MY9221::~MY9221() {
maa_result_t error = MAA_SUCCESS;
error = maa_gpio_close (m_dataPinCtx);
if (error != MAA_SUCCESS) {
maa_result_print(error);
}
error = maa_gpio_close (m_clkPinCtx);
if (error != MAA_SUCCESS) {
maa_result_print(error);
}
}
maa_result_t
MY9221::setBarLevel (uint8_t level) {
if (level > 10) {
return MAA_ERROR_INVALID_PARAMETER;
}
send16bitBlock (CMDMODE);
for(uint8_t block_idx = 0; block_idx < 12; block_idx++) {
uint32_t state = (block_idx < level) ? BIT_HIGH : BIT_LOW;
send16bitBlock (state);
}
lockData ();
}
maa_result_t
MY9221::lockData () {
maa_result_t error = MAA_SUCCESS;
error = maa_gpio_write (m_dataPinCtx, LOW);
usleep(100);
for(int idx = 0; idx < 4; idx++) {
error = maa_gpio_write (m_dataPinCtx, HIGH);
error = maa_gpio_write (m_dataPinCtx, LOW);
}
}
maa_result_t
MY9221::send16bitBlock (short data) {
maa_result_t error = MAA_SUCCESS;
for (uint8_t bit_idx = 0; bit_idx < MAX_BIT_PER_BLOCK; bit_idx++) {
uint32_t state = (data & 0x8000) ? HIGH : LOW;
error = maa_gpio_write (m_dataPinCtx, state);
state = maa_gpio_read (m_clkPinCtx);
if (state) {
state = LOW;
} else {
state = HIGH;
}
error = maa_gpio_write (m_clkPinCtx, state);
data <<= 1;
}
}

58
src/ledbar/my9221.h Normal file
View File

@ -0,0 +1,58 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <string>
#include <maa/aio.h>
#include <maa/gpio.h>
#define MAX_BIT_PER_BLOCK 16
#define CMDMODE 0x0000
#define BIT_HIGH 0x00ff
#define BIT_LOW 0x0000
#define HIGH 1
#define LOW 0
namespace upm {
class MY9221 {
public:
MY9221 (uint8_t di, uint8_t dcki);
~MY9221 ();
maa_result_t setBarLevel (uint8_t level);
std::string name()
{
return m_name;
}
private:
maa_result_t lockData ();
maa_result_t send16bitBlock (short data);
std::string m_name;
maa_gpio_context m_clkPinCtx;
maa_gpio_context m_dataPinCtx;
};
}

View File

@ -0,0 +1,8 @@
%module pyupm_my9221
%feature("autodoc", "3");
%include "my9221.h"
%{
#include "my9221.h"
%}

View File

@ -0,0 +1,4 @@
set (libname "nrf24l01")
add_library (nrf24l01 SHARED nrf24l01.cxx)
include_directories (${MAA_INCLUDE_DIR})
target_link_libraries (nrf24l01 ${MAA_LIBRARIES})

View File

@ -0,0 +1,7 @@
%module jsupm_nrf24l01
%{
#include "nrf24l01.h"
%}
%include "nrf24l01.h"

319
src/nrf24l01/nrf24l01.cxx Normal file
View File

@ -0,0 +1,319 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <iostream>
#include <unistd.h>
#include "nrf24l01.h"
using namespace upm;
NRF24l01::NRF24l01 (uint8_t cs) {
maa_init();
nrfInitModule (cs, 8);
}
NRF24l01::~NRF24l01 () {
maa_result_t error = MAA_SUCCESS;
error = maa_spi_stop(m_spi);
if (error != MAA_SUCCESS) {
maa_result_print(error);
}
error = maa_gpio_close (m_cePinCtx);
if (error != MAA_SUCCESS) {
maa_result_print(error);
}
error = maa_gpio_close (m_csnPinCtx);
if (error != MAA_SUCCESS) {
maa_result_print(error);
}
}
void
NRF24l01::nrfInitModule (uint8_t chip_select, uint8_t chip_enable) {
maa_result_t error = MAA_SUCCESS;
m_csn = chip_select;
m_ce = chip_enable;
m_channel = 1;
m_csnPinCtx = maa_gpio_init (m_csn);
if (m_csnPinCtx == NULL) {
fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", m_csn);
exit (1);
}
m_cePinCtx = maa_gpio_init (m_ce);
if (m_cePinCtx == NULL) {
fprintf (stderr, "Are you sure that pin%d you requested is valid on your platform?", m_ce);
exit (1);
}
error = maa_gpio_dir (m_csnPinCtx, MAA_GPIO_OUT);
if (error != MAA_SUCCESS) {
maa_result_print (error);
}
error = maa_gpio_dir (m_cePinCtx, MAA_GPIO_OUT);
if (error != MAA_SUCCESS) {
maa_result_print (error);
}
nrfCELow ();
m_spi = maa_spi_init (0);
}
void
NRF24l01::nrfConfigModule() {
/* Set RF channel */
nrfConfigRegister (RF_CH, m_channel);
/* Set length of incoming payload */
nrfConfigRegister (RX_PW_P0, m_payload);
nrfConfigRegister (RX_PW_P1, m_payload);
/* Set length of incoming payload for broadcast */
nrfConfigRegister (RX_PW_P2, m_payload);
/* Start receiver */
nrfPowerUpRX ();
nrfFlushRX ();
}
/* Clocks only one byte into the given MiRF register */
void
NRF24l01::nrfConfigRegister(uint8_t reg, uint8_t value) {
nrfCSOn ();
maa_spi_write (m_spi, W_REGISTER | (REGISTER_MASK & reg));
maa_spi_write (m_spi, value);
nrfCSOff ();
}
void
NRF24l01::nrfPowerUpRX() {
m_ptx = 0;
nrfCELow();
nrfConfigRegister(CONFIG, mirf_CONFIG | ( (1<<PWR_UP) | (1<<PRIM_RX) ) );
nrfCEHigh();
nrfConfigRegister(STATUS,(1 << TX_DS) | (1 << MAX_RT));
}
void
NRF24l01::nrfFlushRX() {
nrfCSOn ();
maa_spi_write (m_spi, FLUSH_RX);
nrfCSOff ();
}
/* Sets the receiving address */
void
NRF24l01::nrfSetRXaddr(uint8_t * addr) {
nrfCELow();
nrfWriteRegister(RX_ADDR_P1, addr, mirf_ADDR_LEN);
nrfCEHigh();
}
/* Sets the transmitting address */
void
NRF24l01::nrfSetTXaddr(uint8_t * addr)
{
/* RX_ADDR_P0 must be set to the sending addr for auto ack to work. */
nrfWriteRegister (RX_ADDR_P0, addr, mirf_ADDR_LEN);
nrfWriteRegister (TX_ADDR, addr, mirf_ADDR_LEN);
}
/* The broadcast address should be 0xFFFFF */
void
NRF24l01::nrfSetBroadcastAddr (uint8_t * addr) {
nrfCELow ();
nrfWriteRegister (RX_ADDR_P2, addr, mirf_ADDR_LEN);
nrfCEHigh ();
}
void
NRF24l01::nrfSetPayload (uint8_t load) {
m_payload = load;
}
void
NRF24l01::nrfWriteRegister(uint8_t reg, uint8_t * value, uint8_t len)
{
nrfCSOn ();
maa_spi_write (m_spi, W_REGISTER | (REGISTER_MASK & reg));
nrfTransmitSync(value, len);
nrfCSOff ();
}
void
NRF24l01::nrfTransmitSync(uint8_t *dataout, uint8_t len){
uint8_t i;
for(i = 0; i < len; i++) {
maa_spi_write (m_spi, dataout[i]);
}
}
/* Checks if data is available for reading */
bool
NRF24l01::nrfDataReady() {
uint8_t status = nrfGetStatus();
if ( status & (1 << RX_DR) ) {
return 1;
}
return !nrfRXFifoEmpty();
}
uint8_t
NRF24l01::nrfGetStatus () {
uint8_t rv;
nrfReadRegister (STATUS, &rv, 1);
return rv;
}
/* Reads an array of bytes from the given start position in the MiRF registers. */
void
NRF24l01::nrfReadRegister (uint8_t reg, uint8_t * value, uint8_t len)
{
nrfCSOn ();
maa_spi_write (m_spi, R_REGISTER | (REGISTER_MASK & reg));
nrfTransferSync (value, value, len);
nrfCSOff ();
}
void
NRF24l01::nrfTransferSync (uint8_t *dataout,uint8_t *datain,uint8_t len) {
uint8_t i;
for(i = 0;i < len;i++) {
datain[i] = maa_spi_write (m_spi, dataout[i]);
}
}
bool
NRF24l01::nrfRXFifoEmpty () {
uint8_t fifo_status;
nrfReadRegister (FIFO_STATUS, &fifo_status, sizeof(fifo_status));
return (fifo_status & (1 << RX_EMPTY));
}
/* Reads payload bytes into data array */
void
NRF24l01::nrfGetData (uint8_t * data)
{
nrfCSOn ();
/* Send cmd to read rx payload */
maa_spi_write (m_spi, R_RX_PAYLOAD);
/* Read payload */
nrfTransferSync(data, data, m_payload);
nrfCSOff ();
nrfConfigRegister(STATUS, (1<<RX_DR));
}
/* Sends a data package to the default address. Be sure to send the correct
* amount of bytes as configured as payload on the receiver. */
void
NRF24l01::nrfSend(uint8_t * value) {
uint8_t status;
status = nrfGetStatus();
while (m_ptx) {
status = nrfGetStatus();
if((status & ((1 << TX_DS) | (1 << MAX_RT)))){
m_ptx = 0;
break;
}
} // Wait until last paket is send
nrfCELow();
nrfPowerUpTX(); // Set to transmitter mode , Power up
nrfCSOn ();
maa_spi_write (m_spi, FLUSH_TX); // Write cmd to flush tx fifo
nrfCSOff ();
nrfCSOn ();
maa_spi_write (m_spi, W_TX_PAYLOAD); // Write cmd to write payload
nrfTransmitSync(value, m_payload); // Write payload
nrfCSOff ();
nrfCEHigh(); // Start transmission
}
void
NRF24l01::nrfSend () {
nrfSend (m_txBuffer);
}
bool
NRF24l01::nrfIsSending () {
uint8_t status;
if (m_ptx) { // Sending mode.
status = nrfGetStatus();
/* if sending successful (TX_DS) or max retries exceded (MAX_RT). */
if((status & ((1 << TX_DS) | (1 << MAX_RT)))){
nrfPowerUpRX();
return false;
}
return true;
}
return false;
}
void
NRF24l01::nrfPowerUpTX () {
m_ptx = 1;
nrfConfigRegister (CONFIG, mirf_CONFIG | ( (1<<PWR_UP) | (0<<PRIM_RX) ) );
}
void
NRF24l01::nrfPowerDown () {
nrfCELow ();
nrfConfigRegister (CONFIG, mirf_CONFIG);
}
maa_result_t
NRF24l01::nrfCEHigh () {
return maa_gpio_write (m_cePinCtx, HIGH);
}
maa_result_t
NRF24l01::nrfCELow () {
return maa_gpio_write (m_cePinCtx, LOW);
}
maa_result_t
NRF24l01::nrfCSOn () {
return maa_gpio_write (m_csnPinCtx, LOW);
}
maa_result_t
NRF24l01::nrfCSOff () {
return maa_gpio_write (m_csnPinCtx, HIGH);
}
void
NRF24l01::nrfListenForChannel() {
if(!nrfIsSending() && nrfDataReady()) {
nrfGetData(m_rxBuffer);
dataRecievedHandler(); /* let know that data arrived */
}
}

180
src/nrf24l01/nrf24l01.h Normal file
View File

@ -0,0 +1,180 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#pragma once
#include <string>
#include <maa/aio.h>
#include <maa/gpio.h>
#include <maa/spi.h>
/* Memory Map */
#define CONFIG 0x00
#define EN_AA 0x01
#define EN_RXADDR 0x02
#define SETUP_AW 0x03
#define SETUP_RETR 0x04
#define RF_CH 0x05
#define RF_SETUP 0x06
#define STATUS 0x07
#define OBSERVE_TX 0x08
#define CD 0x09
#define RX_ADDR_P0 0x0A
#define RX_ADDR_P1 0x0B
#define RX_ADDR_P2 0x0C
#define RX_ADDR_P3 0x0D
#define RX_ADDR_P4 0x0E
#define RX_ADDR_P5 0x0F
#define TX_ADDR 0x10
#define RX_PW_P0 0x11
#define RX_PW_P1 0x12
#define RX_PW_P2 0x13
#define RX_PW_P3 0x14
#define RX_PW_P4 0x15
#define RX_PW_P5 0x16
#define FIFO_STATUS 0x17
/* Bit Mnemonics */
#define MASK_RX_DR 6
#define MASK_TX_DS 5
#define MASK_MAX_RT 4
#define EN_CRC 3
#define CRCO 2
#define PWR_UP 1
#define PRIM_RX 0
#define ENAA_P5 5
#define ENAA_P4 4
#define ENAA_P3 3
#define ENAA_P2 2
#define ENAA_P1 1
#define ENAA_P0 0
#define ERX_P5 5
#define ERX_P4 4
#define ERX_P3 3
#define ERX_P2 2
#define ERX_P1 1
#define ERX_P0 0
#define AW 0
#define ARD 4
#define ARC 0
#define PLL_LOCK 4
#define RF_DR 3
#define RF_PWR 1
#define LNA_HCURR 0
#define RX_DR 6
#define TX_DS 5
#define MAX_RT 4
#define RX_P_NO 1
#define TX_FULL 0
#define PLOS_CNT 4
#define ARC_CNT 0
#define TX_REUSE 6
#define FIFO_FULL 5
#define TX_EMPTY 4
#define RX_FULL 1
#define RX_EMPTY 0
/* Instruction Mnemonics */
#define R_REGISTER 0x00
#define W_REGISTER 0x20
#define REGISTER_MASK 0x1F
#define R_RX_PAYLOAD 0x61
#define W_TX_PAYLOAD 0xA0
#define FLUSH_TX 0xE1
#define FLUSH_RX 0xE2
#define REUSE_TX_PL 0xE3
#define NOP 0xFF
/* Nrf24l settings */
#define mirf_ADDR_LEN 5
#define mirf_CONFIG ((1<<EN_CRC) | (0<<CRCO) )
#define MAX_BUFFER 32
#define HIGH 1
#define LOW 0
namespace upm {
typedef void (* funcPtrVoidVoid) ();
class NRF24l01 {
public:
NRF24l01 (uint8_t cs);
~NRF24l01 ();
std::string name()
{
return m_name;
}
void nrfInitModule (uint8_t chipSelect, uint8_t chipEnable);
void nrfConfigModule ();
void nrfSend (uint8_t *value);
void nrfSend ();
void nrfSetRXaddr (uint8_t * addr);
void nrfSetTXaddr (uint8_t * addr);
void nrfSetBroadcastAddr (uint8_t * addr);
void nrfSetPayload (uint8_t load);
bool nrfDataReady ();
bool nrfIsSending ();
bool nrfRXFifoEmpty ();
bool nrfTXFifoEmpty ();
void nrfGetData (uint8_t * data);
uint8_t nrfGetStatus ();
void nrfTransmitSync (uint8_t *dataout, uint8_t len);
void nrfTransferSync (uint8_t *dataout ,uint8_t *datain, uint8_t len);
void nrfConfigRegister (uint8_t reg, uint8_t value);
void nrfReadRegister (uint8_t reg, uint8_t * value, uint8_t len);
void nrfWriteRegister (uint8_t reg, uint8_t * value, uint8_t len);
void nrfPowerUpRX ();
void nrfPowerUpTX ();
void nrfPowerDown ();
maa_result_t nrfCEHigh ();
maa_result_t nrfCELow ();
maa_result_t nrfCSOn ();
maa_result_t nrfCSOff ();
void nrfFlushRX ();
void nrfListenForChannel();
uint8_t m_rxBuffer[MAX_BUFFER];
uint8_t m_txBuffer[MAX_BUFFER];
funcPtrVoidVoid dataRecievedHandler;
private:
maa_spi_context m_spi;
uint8_t m_ce;
uint8_t m_csn;
uint8_t m_channel;
uint8_t m_ptx;
uint8_t m_payload;
uint8_t m_localAddress[5];
maa_gpio_context m_csnPinCtx;
maa_gpio_context m_cePinCtx;
std::string m_name;
};
}

View File

@ -0,0 +1,8 @@
%module pyupm_nrf24l01
%feature("autodoc", "3");
%include "nrf24l01.h"
%{
#include "nrf24l01.h"
%}