Difference between revisions of "ECE497 Notes on Adafruit"

From eLinux.org
Jump to: navigation, search
m (Initial page)
 
(Removed ECE497 category)
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[Category:ECE497 |Notes]]
+
This is out of date a could be removed.
{{YoderHead}}
 
  
 
Here are notes on using using various [http://adafruit.com/ Adafruit] things.  The main Adafruit git repository is [https://github.com/adafruit here].
 
Here are notes on using using various [http://adafruit.com/ Adafruit] things.  The main Adafruit git repository is [https://github.com/adafruit here].
Line 24: Line 23:
 
A command summary starts on page 30.
 
A command summary starts on page 30.
  
{{YoderFoot}}
+
This will dump some of the registers
 +
 
 +
i2cdump -y -r 0-0x0f 3 0x70 b
 +
 
 +
Setting address 0xa3 turns on a row of LEDS, but hangs the device.
 +
 
 +
== myi2ctest.c ==
 +
I'm able to control the [http://adafru.it/454 RED LED matrix].  The code is in myi2ctest.c.
 +
 
 +
== Adapting LED-Backpack-Library ==
 +
 
 +
I try adapting the [https://github.com/adafruit/Adafruit-LED-Backpack-Library Adafruit-LED-Backpack-Library] and [https://github.com/adafruit/Adafruit-GFX-Library Adafruit-GFX-Library] to using the Linux i2c drivers, but it's not compiling yet.  There's a problem with '''vtable''' not being defined.
 +
 
 +
Some things I did for the conversion:
 +
* There are different type declarations.  In '''hack.h''' I mapped them using:
 +
typedef __u8 uint8_t;
 +
typedef __s8 int8_t;
 +
typedef __u16 uint16_t;
 +
typedef __s16 int16_t;
 +
typedef char boolean;
 +
 
 +
* I mapped usleep to delay
 +
#define delay(x) usleep(1000*x)
 +
 
 +
* Arudino has separate instruction (32K) and data (2K) spaces.  If you have a large table it common to put it into the instruction space [http://blog.makezine.com/2011/08/18/arduino-cookbook-excerpt-large-tables-of-data-in-program-memory/].  This is done using '''PROGMEM'''.  The data is read with '''pgm_read_byte()'  Here are my mappings.
 +
#define PROGMEM
 +
#define pgm_read_byte(x) *(x)
 +
 
 +
* '''_BV''' is used to set a given bit [http://urbanhonking.com/ideasfordozens/2009/05/18/an_tour_of_the_arduino_interna/].
 +
#define _BV(bit) (1 << (bit))
 +
 
 +
* You need the following to call C functions from C++
 +
extern "C" {
 +
    int lookup_i2c_bus(const char *i2cbus_arg);
 +
    int parse_i2c_address(const char *address_arg);
 +
    int open_i2c_dev(int i2cbus, char *filename, size_t size, int quiet);
 +
    int set_slave_addr(int file, int address, int force);
 +
}
 +
 
 +
* The '''-fno-rtti''' flag is needed when compiling [http://zedcode.blogspot.com/2007/02/gcc-c-link-problems-on-small-embedded.html] to removed a ''undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info' '' error
 +
 
 +
* The ''__cxa_pure_virtual'' error is removed with [http://zedcode.blogspot.com/2007/02/gcc-c-link-problems-on-small-embedded.html]
 +
extern "C" void __cxa_pure_virtual(void) {
 +
  // call to a pure virtual function happened ... wow, should never happen ... stop
 +
  while(1);
 +
}
 +
 
 +
But even with all this work it's still not compiling!

Latest revision as of 06:22, 24 October 2012

This is out of date a could be removed.

Here are notes on using using various Adafruit things. The main Adafruit git repository is here.

LED Backpack

Here are some leads for interfacing the Small 1.2" 8x8 Bi-Color (Red/Green) Square LED Matrix.

git repositories:

The LED backpack using the HT16K33 LED controller.

The LED startup sequence seems to be:

  • Send 0x21 to start the oscillator (Page 10)
  • Send 0x81 to turn the display on and blinking off (Page 11)
  • Send 0xef to set brightness to full (Page 15)
  • Send 0x00 to start adding at 0 (Page 13)

A command summary starts on page 30.

This will dump some of the registers

i2cdump -y -r 0-0x0f 3 0x70 b

Setting address 0xa3 turns on a row of LEDS, but hangs the device.

myi2ctest.c

I'm able to control the RED LED matrix. The code is in myi2ctest.c.

Adapting LED-Backpack-Library

I try adapting the Adafruit-LED-Backpack-Library and Adafruit-GFX-Library to using the Linux i2c drivers, but it's not compiling yet. There's a problem with vtable not being defined.

Some things I did for the conversion:

  • There are different type declarations. In hack.h I mapped them using:
typedef __u8	uint8_t;
typedef __s8	int8_t;
typedef __u16	uint16_t;
typedef __s16	int16_t;
typedef char	boolean;
  • I mapped usleep to delay
#define delay(x)	usleep(1000*x)
  • Arudino has separate instruction (32K) and data (2K) spaces. If you have a large table it common to put it into the instruction space [1]. This is done using PROGMEM. The data is read with pgm_read_byte()' Here are my mappings.
#define PROGMEM
#define pgm_read_byte(x)	*(x)
  • _BV is used to set a given bit [2].
#define _BV(bit) (1 << (bit))
  • You need the following to call C functions from C++
extern "C" {
    int lookup_i2c_bus(const char *i2cbus_arg);
    int parse_i2c_address(const char *address_arg);
    int open_i2c_dev(int i2cbus, char *filename, size_t size, int quiet);
    int set_slave_addr(int file, int address, int force);
}
  • The -fno-rtti flag is needed when compiling [3] to removed a undefined reference to `vtable for __cxxabiv1::__vmi_class_type_info' error
  • The __cxa_pure_virtual error is removed with [4]
extern "C" void __cxa_pure_virtual(void) {
 // call to a pure virtual function happened ... wow, should never happen ... stop
 while(1);
}

But even with all this work it's still not compiling!