Difference between revisions of "AsDevices"

From ArmadeusWiki
Jump to: navigation, search
Line 49: Line 49:
 
=== SPI ===
 
=== SPI ===
  
 +
==== Usage ====
 
To use as_spi_* function, the kernel module spidev is required. See [[SPI]]
 
To use as_spi_* function, the kernel module spidev is required. See [[SPI]]
 
page to know how to configure it.
 
page to know how to configure it.
Line 60: Line 61:
  
 
Full description of the API can be found in this header, available on
 
Full description of the API can be found in this header, available on
[http://armadeus.git.sourceforge.net/git/gitweb.cgi?p=armadeus/armadeus;a=blob_plain;f=target/packages/as_devices/c/as_spi.h;hb=HEAD sourceforge repository]. Functions are not all implemented, if ''TODO'' in
+
[http://armadeus.git.sourceforge.net/git/gitweb.cgi?p=armadeus/armadeus;a=blob_plain;f=target/packages/as_devices/c/as_spi.h;hb=HEAD sourceforge repository].
comment it needed to be done.
+
  
The three mains usefull functions used to communicate with a slave SPI device
+
==== Example ====
 +
 
 +
The three mains useful functions used to communicate with a slave SPI device
 
are :
 
are :
  
Line 87: Line 89:
  
 
This function forge spi messages on MOSI pin and return MISO message.
 
This function forge spi messages on MOSI pin and return MISO message.
 +
 
=== GPIO ===
 
=== GPIO ===
 +
 +
==== Usage ====
 +
 +
To use as_gpio_* functions, the kernel module gpio is required. See [[GPIO]] page to know how to configure it.
 +
 +
Once the special files ''/dev/gpio/*'' are available , as_gpio library can be use including header as_gpio.h in the C source code of application.
 +
 +
<source lang="C">
 +
#include "as_gpio.h"
 +
</source>
 +
 +
==== Example ====
 +
 +
To examples are given, one for lightening led D14 and one to use blocking read on switch S1. This two example are made for apf27Dev daughter card.
 +
 +
* '''Lightening led'''
 +
With as_gpio, each pin port can be openned separately. The as_gpio_open() function return a pointer on gpio pin structure declared like it :
 +
 +
<source lang="C">
 +
struct as_gpio_device *pf14;
 +
</source>
 +
 +
On apf27Dev, D14 is plugged on port F pin 14, then to open it :
 +
 +
<source lang="C">
 +
pf14 = as_gpio_open('F', 14);
 +
</source>
 +
 +
GPIO must be configured in ouput mode :
 +
 +
<source lang="C">
 +
as_gpio_set_pin_direction(pf14, 1);
 +
</source>
 +
 +
Then to switch led value, juste use set_value function:
 +
 +
<source lang="C">
 +
as_gpio_set_pin_value(pf14, 1); /* led off */
 +
...
 +
as_gpio_set_pin_value(pf14, 0); /* led on */
 +
</source>
 +
 +
Note that because off led wiring, led polarity is inverted (to light on set 0).
 +
 +
Once gpio pin usage is terminated, it must be closed :
 +
 +
<source lang="C">
 +
as_gpio_close(pf14);
 +
</source>
 +
 +
* '''Pressing button'''
 +
 +
 
=== MAX1027 ===
 
=== MAX1027 ===
 
=== MAX5821 ===
 
=== MAX5821 ===

Revision as of 15:01, 8 September 2010

Page under construction... Construction.png Informations on this page are not guaranteed !!

AsDevices is an ARMadeus specific library that simplify APF-board devices usage for developers. This library is written to be used with C, C++, Python, LUA, (Java?) languages. The core is written in C and other languages support is done with "wrappers".

Note Note: This library is under development, see the Development planning. to know which fonctionnality is finnished.


Install AsDevices on target

The library is included in Buildroot menu, to use it just select it in «make menuconfig» :

Package Selection for the target  --->
  *** Armadeus specific packages ***
  Armadeus specific tools/utilities  --->   
    [*] as_devices 

The base library is in C, to use it with C++ or Python, select the wrapper you want.


Using library in C

All functions in AsDevices library are constructed on the same way. An as_*_open() function return a device structure or an int that represent the device used. All function take this device structure in first parameter, and a function as_*_close() close the device :

struct as_devicename_dev * as_devicename_open(<some parameters>);

as_devicename_do-something-with-device(struct as_devicename_dev *aDev, <some parameters>);

int as_devicename_close(struct as_devicename_dev *aDev);

For each library, full documentation can be found in C header in directory target/packages/as_devices/c.

I²C

as_i2c_* functions are used to access device on i²c bus that doesn't have linux driver. If you want to access an i²c device, please find out if a drive already exit before to use this method.

To open the bus, you have to know its number. On apf9328 and apf27 only two bus are present number 0 and number 1. the open function return an int like open file handler :

int as_i2c_open(unsigned int i2c_id);

SPI

Usage

To use as_spi_* function, the kernel module spidev is required. See SPI page to know how to configure it.

Once the special file /dev/spidevx.x is available in the kernel, as_spi library can be used including the header as_spi.h in your C source code :

#include "as_spi.h"

Full description of the API can be found in this header, available on sourceforge repository.

Example

The three mains useful functions used to communicate with a slave SPI device are :

int as_spi_open(const unsigned char *aSpidev_name);

To open the /dev/spidevx.x special spi file. This function return a file handler that will be used for all othes as_spi_* function.

void as_spi_close(int aFd);

As its name said, to close the device.

uint32_t as_spi_msg(int aFd, 
                    uint32_t aMsg, 
                    size_t aLen,
                    uint32_t aSpeed);

This function forge spi messages on MOSI pin and return MISO message.

GPIO

Usage

To use as_gpio_* functions, the kernel module gpio is required. See GPIO page to know how to configure it.

Once the special files /dev/gpio/* are available , as_gpio library can be use including header as_gpio.h in the C source code of application.

#include "as_gpio.h"

Example

To examples are given, one for lightening led D14 and one to use blocking read on switch S1. This two example are made for apf27Dev daughter card.

  • Lightening led

With as_gpio, each pin port can be openned separately. The as_gpio_open() function return a pointer on gpio pin structure declared like it :

 struct as_gpio_device *pf14;

On apf27Dev, D14 is plugged on port F pin 14, then to open it :

 pf14 = as_gpio_open('F', 14);

GPIO must be configured in ouput mode :

 as_gpio_set_pin_direction(pf14, 1);

Then to switch led value, juste use set_value function:

 as_gpio_set_pin_value(pf14, 1); /* led off */
 ...
 as_gpio_set_pin_value(pf14, 0); /* led on */

Note that because off led wiring, led polarity is inverted (to light on set 0).

Once gpio pin usage is terminated, it must be closed :

 as_gpio_close(pf14);
  • Pressing button


MAX1027

MAX5821

93LCXX

PWM

Using library in Python

To use AsDevices in Python, select the python wrapper in menuconfig as follow :

Package Selection for the target  --->
  *** Armadeus specific packages ***
  Armadeus specific tools/utilities  --->   
    [*] as_devices 
    [*]   wrapper Python

then compile bsp and flash it on your board.

Once done, just import the module AsDevices to use all function available in library:

import AsDevice


Using library in C++

TODO

Using library in LUA

TODO

Development planning

AsDevices is not finished, following table indicates the remaining work:

Name C functions C++ wrapper Python wrapper Python class LUA wrapper description
i2c Ok NOK NOK NOK compile Drive I2C
spi Ok, not fully tested NOK NOK NOK NOK Drive SPI
gpio Ok NOK Ok Ok NOK Drive GPIO
max1027 Ok for SLOW mode NOK NOK NOK NOK Drive Analog to Digital chip MAX1027
max5821 OK NOK NOK NOK NOK Drive Digital to Analog chip MAX5821
93LCxx OK NOK NOK NOK NOK EEPROM memory on SPI.
PWM OK NOK NOK NOK NOK