Forth Lesson 22: Difference between revisions
(Describe some canned commands) |
(Added camera test) |
||
Line 131: | Line 131: | ||
| d# 108 gpio>mfpr . |
| d# 108 gpio>mfpr . |
||
|} |
|} |
||
==== Camera Test ==== |
|||
The camera test turns on the camera chip and lets you access internal camera chip registers via its I2C bus interface. |
|||
{| class="wikitable" |
|||
|- |
|||
! Command |
|||
! Stack |
|||
! Description |
|||
! Example |
|||
|- |
|||
| test-camera-i2c |
|||
| ( -- ) |
|||
| Turns on the camera and dumps its internal registers |
|||
| test-camera-i2c |
|||
|- |
|||
| start-camera |
|||
| ( -- ) |
|||
| Sets up the camera clocks and pads, powers on and resets the camera sensor chip |
|||
| start-camera |
|||
|- |
|||
| ov@ |
|||
| ( reg# -- value ) |
|||
| Reads an internal camera register via I2C |
|||
| 5 ov@ . |
|||
|- |
|||
| ov! |
|||
| ( value reg# -- ) |
|||
| Writes an internal camera register via I2C |
|||
| 4 12 ov! |
|||
|- |
|||
| ov-dump |
|||
| ( -- ) |
|||
| Displays a bunch of camera registers |
|||
| ov-dump |
|||
|} |
|||
==== Accessing Arbitrary Devices ==== |
==== Accessing Arbitrary Devices ==== |
Revision as of 21:52, 20 May 2011
Using Forth Under Linux
You can run Forth under Linux and use it to inspect I/O devices.
On XO-1.75
Get http://dev.laptop.org/~wmb/sdkit-arm.tgz . Unpack it into your home directory on an XO-1.75 .
$ tar xfz sdkit-arm.tgz
Then:
$ cd sdkit-arm $ sudo -s # ./sdkit.sh ok
sdkit comes up in hex mode, so you can enter and display numbers in hex without additional qualifiers. To enter a decimal number, precede it with "d# ", e.g. "d# 123"
GPIO Access
Command | Stack | Description | Example |
---|---|---|---|
gpio-pin@ | ( gpio# -- flag ) | Flag is true if GPIO pin is high | d# 108 gpio-pin@ . |
gpio-out? | ( gpio# -- flag ) | Flag is true if GPIO is an output | d# 108 gpio-out? . |
gpio-set | ( gpio# -- ) | Drives GPIO high | d# 108 gpio-set |
gpio-clr | ( gpio# -- ) | Drives GPIO low | d# 108 gpio-clr |
gpio-rise@ | ( gpio# -- flag ) | Flag is true if rising edge detected | d# 108 gpio-rise@ . |
gpio-fall@ | ( gpio# -- flag ) | Flag is true if falling edge detected | d# 108 gpio-fall@ . |
gpio-edge@ | ( gpio# -- flag ) | Flag is true if edge detected | d# 108 gpio-edge@ . |
gpio-clr-edge | ( gpio# -- ) | Clears GPIO edge detector | d# 108 gpio-clr-edge |
gpio-dir-out | ( gpio# -- ) | Sets GPIO direction to output | d# 108 gpio-dir-out |
gpio-dir-in | ( gpio# -- ) | Sets GPIO direction to input | d# 108 gpio-dir-out |
gpio-set-rer | ( gpio# -- ) | Enables rising edge detection | d# 108 gpio-set-rer |
gpio-clr-rer | ( gpio# -- ) | Disables rising edge detection | d# 108 gpio-set-rer |
gpio-set-fer | ( gpio# -- ) | Enables falling edge detection | d# 108 gpio-set-fer |
gpio-clr-fer | ( gpio# -- ) | Disables falling edge detection | d# 108 gpio-set-fer |
Multi-Function Pin Register Access
The Multi-Function Pin Registers (MFPRs) control the assignment of chip pins to internal functions, and also control characteristics of those pins, such as drive strength, pull up/down resistors, etc. Since each multi-function pins can be used as a GPIO, we use the GPIO number to designate which pin we are interested in.
Command | Stack | Description | Example |
---|---|---|---|
af@ | ( gpio# -- function ) | Returns the MFPR setting for gpio# | d# 108 af@ . |
af! | ( function gpio# -- ) | Sets the MFPR for gpio# | h# a0c0 d# 108 af! |
dump-mprs | ( -- ) | Displays a table of all MFPR settings | dump-mfprs |
gpio>mfpr | ( gpio# -- address ) | Returns the address of the MFPR register for gpio# | d# 108 gpio>mfpr . |
Camera Test
The camera test turns on the camera chip and lets you access internal camera chip registers via its I2C bus interface.
Command | Stack | Description | Example |
---|---|---|---|
test-camera-i2c | ( -- ) | Turns on the camera and dumps its internal registers | test-camera-i2c |
start-camera | ( -- ) | Sets up the camera clocks and pads, powers on and resets the camera sensor chip | start-camera |
ov@ | ( reg# -- value ) | Reads an internal camera register via I2C | 5 ov@ . |
ov! | ( value reg# -- ) | Writes an internal camera register via I2C | 4 12 ov! |
ov-dump | ( -- ) | Displays a bunch of camera registers | ov-dump |
Accessing Arbitrary Devices
In addition to the "canned" access words for specific devices, you can manually access any device you wish, using the "mmap" command to assign a virtual address to the I/O device's physical address.
Command | Stack | Description | Example |
---|---|---|---|
mmap | ( phys-address size -- virt-address ) | Assigns a virtual address to a physical device address | d4050000 1000 mmap constant clock-unit-base |
The physical address and size must both be multiples of 0x1000, i.e. their low three hex digits must be 0.
You can add offsets to the virtual address to access registers within the range {virtual-address .. virtual-address+size-1}. For example:
ok d4050000 1000 mmap constant clock-unit ok clock-unit 24 + l@ .