Wixel SDK
|
#include <cc2511_types.h>
Go to the source code of this file.
Macros | |
#define | LOW 0 |
#define | HIGH 1 |
#define | HIGH_IMPEDANCE 0 |
#define | PULLED 1 |
Functions | |
void | setDigitalOutput (uint8 pinNumber, BIT value) __reentrant |
Configures the specified pin as a digital output. More... | |
void | setDigitalInput (uint8 pinNumber, BIT pulled) __reentrant |
Configures the specified pin as an input. More... | |
BIT | isPinHigh (uint8 pinNumber) __reentrant |
Returns the current input or output value of the pin. More... | |
void | setPort0PullType (BIT pullType) __reentrant |
void | setPort1PullType (BIT pullType) __reentrant |
void | setPort2PullType (BIT pullType) __reentrant |
The gpio.lib
library provides functions for using the CC2511's pins as general purpose inputs or outputs (GPIO). Every pin on the CC2511 that has a name starting with P can be configured as a digital input or digital output.
The functions in this library allow for simpler programmatic approaches to working with digital I/O since you no longer have to deal with a multitude of pin-specific registers.
The pins on the CC2511 are divided into three ports: Port 0 (P0), Port 1 (P1), and Port 2 (P2). Every pin's name is prefixed by the name of the port it is on. For example, P0_3 starts with "P0" so it is a pin on Port 0.
On the Wixel, none of the pins on Port 0 and Port 1 are tied to any on-board hardware so they completely free to be used as GPIO.
When the Wixel starts up, all the pins on Port 0 and Port 1 will be inputs with internal pull-up resistors enabled except P1_0 and P1_1, which do not have internal pull-up or pull-down resistors
This library supports Port 2, but all of the Wixel's Port 2 pins are handled by the functions declared in board.h so you should not need to manipulate them with this library.
Most of the functions in this library take a pin number as their first argument. These numbers are computed by multiplying the first digit in the pin name by ten and adding it to the second digit, as shown in the table below.
Pin | pinNumber parameter |
---|---|
P0_0 | 0 |
P0_1 | 1 |
P0_2 | 2 |
P0_3 | 3 |
P0_4 | 4 |
P0_5 | 5 |
P1_0 | 10 |
P1_1 | 11 |
P1_2 | 12 |
P1_3 | 13 |
P1_4 | 14 |
P1_5 | 15 |
P1_6 | 16 |
P1_7 | 17 |
P2_0 | 20 |
P2_1 | 21 |
P2_2 | 22 |
P2_3 | 23 |
P2_4 | 24 |
All the functions in this library are declared as reentrant, which means it is safe to call them in your main loop and also in your interrupt service routines (ISRs). However, if you are using these functions in an ISR, you should make sure that you have no code in your main loop that does a non-atomic read-modify-write operation on any of the I/O registers that are changed in the interrupt. The risk is that the interrupt could fire after while the read-modify-write operation is in progress, after the register has been read but before it has been written. Then when the register is written by the main loop, the change made by the ISR will be unintentionally lost.
For example, it would be bad if you called setDigitalOutput(10, 1)
in an interrupt and in your main loop you had some code like:
It is OK to have code like P1DIR |= VALUE;
in your main loop because that compiles to a single instruction, so it should be atomic.
Calling the functions in this library will be slower than manipulating the I/O registers yourself, but the overhead should be roughly the same for each pin.
This library (git revision 4de9ee1f) was tested with SDCC 3.0.0 (#6037) and it was found that an I/O line could be toggled once every 3.2 microseconds by calling setDigitalOutput() several times in a row.
To use your digital I/O pins correctly, there are several things you should be aware of:
Definition in file gpio.h.
#define HIGH 1 |
#define HIGH_IMPEDANCE 0 |
Specifies that the input pin should be a high-impedance input with no pull-up or pull-down resistor enabled. See setDigitalInput().
#define LOW 0 |
#define PULLED 1 |
Specifies that the pin should have a 20 kilohm pull-up or pull-down enabled. See setDigitalInput().
Returns the current input or output value of the pin.
pinNumber | Should be one of the pin numbers listed in the table above (e.g. 12). |
The return value represents a digital reading of the voltage on the pin. According to the "DC Characteristics" section of the CC2511 datasheet, voltages below 30% of VDD (typically 0.99 V on the Wixel) will read as 0, while voltages above 70% of VDD (typically 2.31 V on the Wixel) will read as 1.
This function is intended to be used for pins that are configured as inputs. For a pin configured as an output, it can be used, but it might sometimes give unexpected results in case the current voltage has not reached the voltage that the pin is configured to drive it to.
This function simply returns the bit value of the port. For example, calling isPinHigh(14)
will have the effect as reading P1_4
(but the function call will be slower).
Configures the specified pin as an input.
pinNumber | Should be one of the pin numbers listed in the table above (e.g. 12). |
pulled | Should be one of the following:
|
This function first sets the pull type, then it sets the pin direction. For example, calling setDigitalInput(15, PULLED)
will have the same effect as (but be slower than) this:
Note: The pins P1_0 and P1_1 do NOT have internal pull-up or pull-down resistors, so the second argument to this function does not have any effect when configuring either of those pins.
Configures the specified pin as a digital output.
pinNumber | Should be one of the pin numbers listed in the table above (e.g. 12). |
value | Should be one of the following: |
This function will not work if the pin has previously been configured as a peripheral function pin; the bit for this pin in P0SEL/P1SEL/P2SEL must be 0.
This function first sets the output value, then it sets the pin direction. For example, calling setDigitalOutput(3, HIGH)
will have the same effect as (but be slower than) this:
void setPort0PullType | ( | BIT | pullType | ) |
Selects whether Port 0 will have internal pull-down or pull-up resistors.
pullType | Specifies the voltage that the resistors will pull to. Should be either LOW (0) or HIGH (1). |
The resistors can be disabled individually for each pin using setDigitalInput(), but it is impossible to have pull-up and pull-down resistors enabled simultaneously for different pins on the same port.
void setPort1PullType | ( | BIT | pullType | ) |
Same as setPort0PullType() except this function affects Port 1.
void setPort2PullType | ( | BIT | pullType | ) |
Same as setPort0PullType() except this function affects Port 2. This function is included for the sake of completeness, but it should not be used on a Wixel because all of the pins on Port 2 are managed by the functions declared in board.h.