Difference between revisions of "AsDevices"
Line 104: | Line 104: | ||
==== Example ==== | ==== Example ==== | ||
− | + | Two 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''' | * '''Lightening led''' | ||
Line 110: | Line 110: | ||
<source lang="C"> | <source lang="C"> | ||
+ | int ret; /* for returning value */ | ||
struct as_gpio_device *pf14; | struct as_gpio_device *pf14; | ||
</source> | </source> | ||
Line 122: | Line 123: | ||
<source lang="C"> | <source lang="C"> | ||
− | as_gpio_set_pin_direction(pf14, 1); | + | ret = as_gpio_set_pin_direction(pf14, 1); |
</source> | </source> | ||
Line 128: | Line 129: | ||
<source lang="C"> | <source lang="C"> | ||
− | as_gpio_set_pin_value(pf14, 1); /* led off */ | + | ret = as_gpio_set_pin_value(pf14, 1); /* led off */ |
... | ... | ||
− | as_gpio_set_pin_value(pf14, 0); /* led on */ | + | ret = as_gpio_set_pin_value(pf14, 0); /* led on */ |
</source> | </source> | ||
Line 143: | Line 144: | ||
* '''Pressing button''' | * '''Pressing button''' | ||
+ | The button S1 can be used to test interrupt capability of gpio. The button is plugged on gpio port F pin 13. | ||
+ | After declaring the as_gpio_device structure, the pin port can be openned : | ||
+ | |||
+ | <source lang="C"> | ||
+ | struct as_gpio_device *pf13; | ||
+ | [...] | ||
+ | |||
+ | pf13 = as_gpio_open('F', 13); | ||
+ | </source> | ||
+ | |||
+ | To stuff must be configured before using it as interruption source, direction and IRQ mode. | ||
+ | |||
+ | '''direction''' | ||
+ | <source lang="C"> | ||
+ | ret = as_gpio_set_pin_direction(pf13, 0); /* set switch as input */ | ||
+ | </source> | ||
+ | |||
+ | '''IRQ mode''' | ||
+ | There is four IRQ mode : | ||
+ | * '''GPIO_IRQ_MODE_NOINT ''': No interrupt, the processor will ignore event on this gpio. | ||
+ | * '''GPIO_IRQ_MODE_RISING ''': rising edge, the processor will generate an interruption on rising edge of gpio pin. | ||
+ | * '''GPIO_IRQ_MODE_FALLING''': falling edge, the processor will generate an interruption on falling edge of gpio pin. | ||
+ | * '''GPIO_IRQ_MODE_BOTH ''': both, the processor will generate an interruption on both rising or falling edge of gpio. | ||
+ | |||
+ | <source lang="C"> | ||
+ | ret = as_gpio_set_irq_mode(pf13, GPIO_IRQ_MODE_FALLING); /* interrupt will be generated on pushed button */ | ||
+ | </source> | ||
+ | |||
+ | To capture interruption, the blocking read function can be used with a timeout. If no interruption is raised after the timeout time, read function end with error value -10. | ||
+ | |||
+ | <source lang="C"> | ||
+ | ret = as_gpio_blocking_get_pin_value(pf13, 3, 0); /* wait for interruption for 3 seconds and 0 µs) */ | ||
+ | if(ret == -10) | ||
+ | printf("Timeout\n"); | ||
+ | </source> | ||
=== MAX1027 === | === MAX1027 === |
Revision as of 14:36, 8 September 2010
Page under construction... 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: This library is under development, see the Development planning. to know which fonctionnality is finnished. |
Contents
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
Two 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 :
int ret; /* for returning value */
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 :
ret = as_gpio_set_pin_direction(pf14, 1);
Then to switch led value, juste use set_value function:
ret = as_gpio_set_pin_value(pf14, 1); /* led off */
...
ret = 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
The button S1 can be used to test interrupt capability of gpio. The button is plugged on gpio port F pin 13. After declaring the as_gpio_device structure, the pin port can be openned :
struct as_gpio_device *pf13;
[...]
pf13 = as_gpio_open('F', 13);
To stuff must be configured before using it as interruption source, direction and IRQ mode.
direction
ret = as_gpio_set_pin_direction(pf13, 0); /* set switch as input */
IRQ mode There is four IRQ mode :
- GPIO_IRQ_MODE_NOINT : No interrupt, the processor will ignore event on this gpio.
- GPIO_IRQ_MODE_RISING : rising edge, the processor will generate an interruption on rising edge of gpio pin.
- GPIO_IRQ_MODE_FALLING: falling edge, the processor will generate an interruption on falling edge of gpio pin.
- GPIO_IRQ_MODE_BOTH : both, the processor will generate an interruption on both rising or falling edge of gpio.
ret = as_gpio_set_irq_mode(pf13, GPIO_IRQ_MODE_FALLING); /* interrupt will be generated on pushed button */
To capture interruption, the blocking read function can be used with a timeout. If no interruption is raised after the timeout time, read function end with error value -10.
ret = as_gpio_blocking_get_pin_value(pf13, 3, 0); /* wait for interruption for 3 seconds and 0 µs) */
if(ret == -10)
printf("Timeout\n");
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 |