dey-examples: Rework the examples to be launch-ready
Signed-off-by: Francisco Gil <francisco.gilmartinez@digi.com>
This commit is contained in:
parent
58469e08da
commit
3b7bbdbf65
|
|
@ -22,7 +22,7 @@ CFLAGS += $(shell pkg-config --cflags libdigiapix)
|
|||
LDLIBS += $(shell pkg-config --libs libdigiapix)
|
||||
|
||||
$(BINARY): main.o
|
||||
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@ -lm
|
||||
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
|
||||
|
||||
.PHONY: install
|
||||
install: $(BINARY)
|
||||
|
|
|
|||
|
|
@ -8,61 +8,32 @@ takes periodic samples and prints the raw value and the value in mv.
|
|||
|
||||
The ADC lines used in the sample are mapped as follows in the Digi Boards:
|
||||
- **CCIMX6 SBC**: PMIC_ADCIN1 (GPIO Connector Pin 1).
|
||||
- **CCIMX6Plus SBC**: PMIC_ADCIN1 (GPIO Connector Pin 1).
|
||||
- **CCIMX6UL SBC Express**: ADC1_IN4 (Expansion Connector Pin 7).
|
||||
- **CCIMX6UL SBC Pro**: ADC1_IN2 (GPIO Connector Pin 13).
|
||||
|
||||
The following device tree modifications are required for the sample to work:
|
||||
- **CCIMX6 SBC**: _No device tree modifications are required._
|
||||
- **CCIMX6UL SBC Express**:
|
||||
```
|
||||
&adc1 {
|
||||
pinctrl-names = "default";
|
||||
pinctrl-0 = <&pinctrl_adc1>;
|
||||
adc-ch-list = <4>;
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&iomuxc {
|
||||
imx6ul-ccimx6ul {
|
||||
pinctrl_adc1: adc1grp {
|
||||
fsl,pins = <
|
||||
MX6UL_PAD_GPIO1_IO04__GPIO1_IO04 0xb0
|
||||
>;
|
||||
};
|
||||
};
|
||||
};
|
||||
```
|
||||
- **CCIMX6UL SBC Pro**:
|
||||
```
|
||||
&adc1 {
|
||||
pinctrl-names = "default";
|
||||
pinctrl-0 = <&pinctrl_adc1>;
|
||||
adc-ch-list = <2>;
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
&iomuxc {
|
||||
imx6ul-ccimx6ul {
|
||||
pinctrl_adc1: adc1grp {
|
||||
fsl,pins = <
|
||||
MX6UL_PAD_GPIO1_IO02__GPIO1_IO02 0xb0
|
||||
>;
|
||||
};
|
||||
};
|
||||
};
|
||||
```
|
||||
|
||||
Running the application
|
||||
-----------------------
|
||||
Once the binary is in the target, launch the application:
|
||||
|
||||
```
|
||||
#> apix-adc-example [adc_chip adc_channel interval number_of_samples]
|
||||
# ./apix-adc-example
|
||||
Example application using libdigiapix ADC support
|
||||
|
||||
Usage: apix-adc-example <adc_chip> <adc_channel> <interval> <number_of_samples>
|
||||
|
||||
<adc_chip> ADC chip number or alias
|
||||
<adc_channel> ADC channel number or alias
|
||||
<interval> Time interval for sampling
|
||||
<number_of_samples> Number of samples to get
|
||||
|
||||
Alias for ADC can be configured in the library config file
|
||||
|
||||
```
|
||||
Where:
|
||||
- 'adc_chip' the ADC chip number.
|
||||
- 'adc_channel' the ADC channel number.
|
||||
- 'interval' is the time interval between samples.
|
||||
- 'number_of_samples' is the number of samples to take.
|
||||
|
||||
If no arguments are provided, the example will use the default values:
|
||||
- For the interfaces, default values are configured in "/etc/libdigiapix.conf"
|
||||
- Specific application default values are defined in the main file.
|
||||
|
||||
Compiling the application
|
||||
-------------------------
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
#include <errno.h>
|
||||
#include <libgen.h>
|
||||
#include <limits.h>
|
||||
#include <math.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
|
@ -28,6 +27,10 @@
|
|||
#define ARG_ADC_CHIP 0
|
||||
#define ARG_ADC_CHANNEL 1
|
||||
|
||||
#define DEFAULT_ADC_ALIAS "DEFAULT_ADC"
|
||||
#define DEFAULT_TIME_INTERVAl 1
|
||||
#define DEFAULT_NUMBER_OF_SAMPLES 10
|
||||
|
||||
static adc_t *adc;
|
||||
|
||||
struct adc_sampling_cb_data {
|
||||
|
|
@ -48,11 +51,12 @@ static void usage_and_exit(char *name, int exitval)
|
|||
"Example application using libdigiapix ADC support\n"
|
||||
"\n"
|
||||
"Usage: %s <adc_chip> <adc_channel> <interval> <number_of_samples> \n\n"
|
||||
"<adc_chip> ADC chip number\n"
|
||||
"<adc_channel> ADC channel number\n"
|
||||
"<adc_chip> ADC chip number or alias\n"
|
||||
"<adc_channel> ADC channel number or alias\n"
|
||||
"<interval> Time interval for sampling\n"
|
||||
"<number_of_samples> Number of samples to get\n"
|
||||
"\n\n"
|
||||
"\n"
|
||||
"Alias for ADC can be configured in the library config file\n"
|
||||
"\n", name);
|
||||
|
||||
exit(exitval);
|
||||
|
|
@ -151,22 +155,26 @@ static int adc_sampling_cb(int sample, void *arg)
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
unsigned int channel, chip, interval;
|
||||
int number_of_samples;
|
||||
int channel = 0, chip = 0, interval = 0, number_of_samples = 0;
|
||||
char *name = basename(argv[0]);
|
||||
struct adc_sampling_cb_data cb_data;
|
||||
|
||||
/* Check input parameters */
|
||||
if (argc != 5) {
|
||||
usage_and_exit(name, EXIT_FAILURE);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (argc == 1) {
|
||||
/* Use default values */
|
||||
chip = ldx_adc_get_chip(DEFAULT_ADC_ALIAS);
|
||||
channel = ldx_adc_get_channel(DEFAULT_ADC_ALIAS);
|
||||
interval = DEFAULT_TIME_INTERVAl;
|
||||
number_of_samples = DEFAULT_NUMBER_OF_SAMPLES;
|
||||
} else if (argc == 5) {
|
||||
/* Parse command line arguments */
|
||||
chip = parse_argument(argv[1], ARG_ADC_CHIP);
|
||||
channel = parse_argument(argv[2], ARG_ADC_CHANNEL);
|
||||
interval = atoi(argv[3]);
|
||||
number_of_samples = atoi(argv[4]);
|
||||
} else {
|
||||
usage_and_exit(name, EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (chip < 0) {
|
||||
printf("Invalid chip number\n");
|
||||
|
|
|
|||
|
|
@ -4,12 +4,26 @@ The example application uses a gpio as input (e.g. a user button) and another
|
|||
one as output (e.g. a user led). The application toggles the output GPIO
|
||||
whenever an interrupt is generated in the input GPIO.
|
||||
|
||||
The GPIOs lines used in the sample are mapped as follows in the Digi Boards:
|
||||
- **CCIMX6 SBC**:
|
||||
- User button: EXP_GPIO_0 (GPIO Connector Pin 6)
|
||||
- User led: USER_LED0 (Connected in the board)
|
||||
- **CCIMX6Plus SBC**:
|
||||
- User button: EXP_GPIO_0 (GPIO Connector Pin 6)
|
||||
- User led: USER_LED0 (Connected in the board)
|
||||
- **CCIMX6UL SBC Express**: ADC1_IN4 (Expansion Connector Pin 7)
|
||||
- User button: GPIO3_IO3 (Connected in the board)
|
||||
- User led: GPIO3_IO11 (Connected in the board)
|
||||
- **CCIMX6UL SBC Pro**: ADC1_IN2 (GPIO Connector Pin 13)
|
||||
- User button: MCA_IO1 (GPIO Connector Pin 7)
|
||||
- User led: USER_LED1 (Connected in the board)
|
||||
|
||||
Running the application
|
||||
-----------------------
|
||||
Once the binary is in the target, launch the application:
|
||||
|
||||
```
|
||||
root@ccimx6ulstarter:~# ./apix-gpio-example
|
||||
# ./apix-gpio-example
|
||||
Example application using libdigiapix GPIO support
|
||||
|
||||
Usage: apix-gpio-example <gpio_in> <gpio_out>
|
||||
|
|
@ -20,6 +34,10 @@ Usage: apix-gpio-example <gpio_in> <gpio_out>
|
|||
Aliases for GPIO numbers can be configured in the library config file
|
||||
```
|
||||
|
||||
If no arguments are provided, the example will use the default values:
|
||||
- For the interfaces, default values are configured in "/etc/libdigiapix.conf"
|
||||
- Specific application default values are defined in the main file.
|
||||
|
||||
Compiling the application
|
||||
-------------------------
|
||||
This example can be compiled using a Digi Embedded Yocto based toolchain. Make
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@
|
|||
#include <libdigiapix/gpio.h>
|
||||
|
||||
#define TEST_LOOPS 6
|
||||
#define DEFAULT_USER_LED_ALIAS "USER_LED"
|
||||
#define DEFAULT_USER_BUTTON_ALIAS "USER_BUTTON"
|
||||
|
||||
static gpio_t *gpio_input;
|
||||
static gpio_t *gpio_output;
|
||||
|
|
@ -152,12 +154,18 @@ int main(int argc, char *argv[])
|
|||
char *name = basename(argv[0]);
|
||||
|
||||
/* Check input parameters */
|
||||
if (argc != 3)
|
||||
usage_and_exit(name, EXIT_FAILURE);
|
||||
|
||||
if (argc == 1) {
|
||||
/* Use default values */
|
||||
button = parse_argument(DEFAULT_USER_BUTTON_ALIAS);
|
||||
led = parse_argument(DEFAULT_USER_LED_ALIAS);
|
||||
} else if (argc == 3) {
|
||||
/* Parse command line arguments */
|
||||
button = parse_argument(argv[1]);
|
||||
led = parse_argument(argv[2]);
|
||||
} else {
|
||||
usage_and_exit(name, EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (button < 0 || led < 0) {
|
||||
printf("Unable to parse button and led GPIOs\n");
|
||||
return EXIT_FAILURE;
|
||||
|
|
|
|||
|
|
@ -12,6 +12,11 @@ The I2C connections for the sample depend on the running platform:
|
|||
- GND: Pin 6
|
||||
- I2C-3 SDA: Pin 2
|
||||
- I2C-3 SCL: Pin 1
|
||||
- **CCIMX6Plus SBC**: I2C connector of the board.
|
||||
- VCC: Pin 3
|
||||
- GND: Pin 6
|
||||
- I2C-3 SDA: Pin 2
|
||||
- I2C-3 SCL: Pin 1
|
||||
- **CCIMX6UL SBC Express**: Expansion connector of the board.
|
||||
- VCC: Pin 1
|
||||
- GND: Pin 6
|
||||
|
|
@ -28,19 +33,22 @@ Running the application
|
|||
Once the binary is in the target, launch the application:
|
||||
|
||||
```
|
||||
#> apix-i2c-example
|
||||
# ./apix-i2c-example
|
||||
Example application using libdigiapix I2C support
|
||||
|
||||
Usage: %s <i2c-bus> <i2c-address> <address-size> <page-size> <page-index>
|
||||
Usage: apix-i2c-example <i2c-bus> <i2c-address> <address-size> <page-size> <page-index>
|
||||
|
||||
<i2c-bus> I2C bus index to use
|
||||
<i2c-bus> I2C bus index to use or alias
|
||||
<i2c-address> Address of the I2C EEPROM memory
|
||||
<address-size> Number of EEPROM memory address bytes
|
||||
<page-size> EEPROM memory page size in bytes
|
||||
<page-index> EEPROM memory page index to use
|
||||
|
||||
Aliases for SPI can be configured in the library config file
|
||||
Aliases for I2C can be configured in the library config file
|
||||
```
|
||||
If no arguments are provided, the example will use the default values:
|
||||
- For the interfaces, default values are configured in "/etc/libdigiapix.conf"
|
||||
- Specific application default values are defined in the main file.
|
||||
|
||||
Compiling the application
|
||||
-------------------------
|
||||
|
|
|
|||
|
|
@ -28,6 +28,12 @@
|
|||
|
||||
#define I2C_TIMEOUT 1
|
||||
|
||||
#define DEFAULT_I2C_ALIAS "DEFAULT_I2C_BUS"
|
||||
#define DEFAULT_I2C_ADDRESS 0x54
|
||||
#define DEFAULT_I2C_ADDRESS_SIZE 2
|
||||
#define DEFAULT_I2C_PAGE_SIZE 128
|
||||
#define DEFAULT_I2C_PAGE_INDEX 0
|
||||
|
||||
static i2c_t *i2c_bus;
|
||||
static unsigned int i2c_address;
|
||||
static int eeprom_page_size, eeprom_addr_size;
|
||||
|
|
@ -47,7 +53,7 @@ static void usage_and_exit(char *name, int exitval)
|
|||
"Example application using libdigiapix I2C support\n"
|
||||
"\n"
|
||||
"Usage: %s <i2c-bus> <i2c-address> <address-size> <page-size> <page-index>\n\n"
|
||||
"<i2c-bus> I2C bus index to use\n"
|
||||
"<i2c-bus> I2C bus index to use or alias\n"
|
||||
"<i2c-address> Address of the I2C EEPROM memory\n"
|
||||
"<address-size> Number of EEPROM memory address bytes\n"
|
||||
"<page-size> EEPROM memory page size in bytes\n"
|
||||
|
|
@ -221,21 +227,28 @@ static int read_page(int page_index, uint8_t *data)
|
|||
int main(int argc, char **argv)
|
||||
{
|
||||
char *name = basename(argv[0]);
|
||||
int page_index;
|
||||
int i2c_bus_nb;
|
||||
int page_index = 0;
|
||||
int i2c_bus_nb = 0;
|
||||
int i;
|
||||
|
||||
/* Check input parameters */
|
||||
if (argc != 6) {
|
||||
usage_and_exit(name, EXIT_FAILURE);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (argc == 1) {
|
||||
/* Use default values */
|
||||
i2c_bus_nb = ldx_i2c_get_bus(DEFAULT_I2C_ALIAS);
|
||||
i2c_address = DEFAULT_I2C_ADDRESS;
|
||||
eeprom_addr_size = DEFAULT_I2C_ADDRESS_SIZE;
|
||||
eeprom_page_size = DEFAULT_I2C_PAGE_SIZE;
|
||||
page_index = DEFAULT_I2C_PAGE_INDEX;
|
||||
} else if (argc == 6) {
|
||||
/* Parse command line arguments */
|
||||
i2c_bus_nb = parse_argument(argv[1]);
|
||||
i2c_address = (unsigned int)strtol(argv[2], NULL, 16);
|
||||
eeprom_addr_size = atoi(argv[3]);
|
||||
eeprom_page_size = atoi(argv[4]);
|
||||
page_index = atoi(argv[5]);
|
||||
} else {
|
||||
usage_and_exit(name, EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (eeprom_addr_size <= 0) {
|
||||
printf("Address size must be greater than 0\n");
|
||||
|
|
|
|||
|
|
@ -9,72 +9,30 @@ The application enables one PWM line of the board using a frequency of
|
|||
|
||||
The PWM lines used in the sample are mapped as follows in the Digi Boards:
|
||||
- **CCIMX6 SBC**: PWM1 - Pin **10** of the parallel video (LCD) connector.
|
||||
- **CCIMX6Plus SBC**: PWM1 - Pin **10** of the parallel video (LCD) connector.
|
||||
- **CCIMX6UL SBC Express**: PWM1 - Pin **27** of the expansion connector.
|
||||
- **CCIMX6UL SBC Pro**: PWM4 - Pin **11** of the GPIO connector.
|
||||
|
||||
The following device tree modifications are required for the sample to work:
|
||||
- **CCIMX6 SBC**:
|
||||
```
|
||||
/* PWM1 */
|
||||
&pwm1 {
|
||||
pinctrl-names = "default";
|
||||
pinctrl-0 = <&pinctrl_pwm1>;
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
/* Pin mux configuration */
|
||||
&iomuxc {
|
||||
imx6q-ccimx6sbc {
|
||||
pinctrl_pwm1: pwm1grp {
|
||||
fsl,pins = <
|
||||
MX6QDL_PAD_DISP0_DAT8__PWM1_OUT 0x110b0
|
||||
>;
|
||||
};
|
||||
};
|
||||
};
|
||||
```
|
||||
- **CCIMX6UL SBC Express**:
|
||||
_No device tree modifications are required._
|
||||
- **CCIMX6UL SBC Pro**:
|
||||
```
|
||||
/* PWM4 */
|
||||
&pwm4 {
|
||||
pinctrl-names = "default";
|
||||
pinctrl-0 = <&pinctrl_pwm4>;
|
||||
clocks = <&clks IMX6UL_CLK_PWM4>,
|
||||
<&clks IMX6UL_CLK_PWM4>;
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
/* Pin mux configuration */
|
||||
&iomuxc {
|
||||
imx6ul-ccimx6ul {
|
||||
pinctrl_pwm4: pwm4grp {
|
||||
fsl,pins = <
|
||||
MX6UL_PAD_GPIO1_IO05__PWM4_OUT 0x110b0
|
||||
>;
|
||||
};
|
||||
};
|
||||
};
|
||||
```
|
||||
|
||||
Running the application
|
||||
-----------------------
|
||||
Once the binary is in the target, launch the application:
|
||||
|
||||
```
|
||||
#> pwm-digiapix-sample
|
||||
# ./apix-pwm-example
|
||||
Example application using libdigiapix PWM support
|
||||
|
||||
Usage: apix-pwm-example <pwm-chip> <pwm-freq>
|
||||
|
||||
<pwm-chip> PWM chip number or alias
|
||||
<pwm-channel> PWM channel number or alias
|
||||
<pwm-freq> Frequency to use (Hz)
|
||||
|
||||
Aliases for PWM can be configured in the library config file
|
||||
```
|
||||
|
||||
The sample applicaion is ready to work with all Digi platforms using the corresponding
|
||||
PWM chip (0 by default) and a frequency of 1000Hz. If a different PWM chip or frequency
|
||||
is required, the application allows 2 additional parameters in order to customize
|
||||
these values:
|
||||
```
|
||||
#> pwm-digiapix-sample [pwm-chip pwm-freq]
|
||||
```
|
||||
Where:
|
||||
- 'pwm-chip' is an optional PWM chip number.
|
||||
- 'pwm-freq' is an optional frequency to use (Hz).
|
||||
If no arguments are provided, the example will use the default values:
|
||||
- For the interfaces, default values are configured in "/etc/libdigiapix.conf"
|
||||
- Specific application default values are defined in the main file.
|
||||
|
||||
Compiling the application
|
||||
-------------------------
|
||||
|
|
|
|||
|
|
@ -24,7 +24,12 @@
|
|||
|
||||
#include <libdigiapix/pwm.h>
|
||||
|
||||
#define DEFAULT_PWM_CHANNEL 0
|
||||
|
||||
#define DEFAULT_PWM_FREQUENCY 1000
|
||||
#define DEFAULT_PWM_ALIAS "DEFAULT_PWM"
|
||||
|
||||
#define ARG_PWM_CHIP 0
|
||||
#define ARG_PWM_CHANNEL 1
|
||||
|
||||
static pwm_t *pwm_line;
|
||||
static int running = 1;
|
||||
|
|
@ -43,7 +48,11 @@ static void usage_and_exit(char *name, int exitval)
|
|||
"\n"
|
||||
"Usage: %s <pwm-chip> <pwm-freq>\n\n"
|
||||
"<pwm-chip> PWM chip number or alias\n"
|
||||
"<pwm-freq> Frequency to use (Hz)\n\n", name);
|
||||
"<pwm-channel> PWM channel number or alias\n"
|
||||
"<pwm-freq> Frequency to use (Hz)\n"
|
||||
"\n"
|
||||
"Aliases for PWM can be configured in the library config file\n"
|
||||
"\n", name);
|
||||
|
||||
exit(exitval);
|
||||
}
|
||||
|
|
@ -92,10 +101,11 @@ static void register_signals(void)
|
|||
* corresponding integer value
|
||||
*
|
||||
* @argv: Argument to parse in string format.
|
||||
* @arg_type: Type of the argument to parse.
|
||||
*
|
||||
* Return: The parsed integer argument, -1 on error.
|
||||
*/
|
||||
static int parse_argument(char *argv)
|
||||
static int parse_argument(char *argv, int arg_type)
|
||||
{
|
||||
char *endptr;
|
||||
long value;
|
||||
|
|
@ -107,27 +117,39 @@ static int parse_argument(char *argv)
|
|||
|| (errno != 0 && value == 0))
|
||||
return -1;
|
||||
|
||||
if (endptr == argv)
|
||||
if (endptr == argv){
|
||||
switch (arg_type) {
|
||||
case ARG_PWM_CHIP:
|
||||
return ldx_pwm_get_chip(endptr);
|
||||
case ARG_PWM_CHANNEL:
|
||||
return ldx_pwm_get_channel(endptr);
|
||||
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int ret, duty_cycle = 10, ascending = 1;
|
||||
int ret, duty_cycle = 10, ascending = 1, pwm_chip, pwm_channel, pwm_freq = 0;
|
||||
char *name = basename(argv[0]);
|
||||
unsigned int pwm_chip, pwm_freq = 0;
|
||||
|
||||
/* Check if the PWM values are passed in the command line. */
|
||||
if (argc != 3)
|
||||
if (argc == 1) {
|
||||
pwm_chip = ldx_pwm_get_chip(DEFAULT_PWM_ALIAS);
|
||||
pwm_channel = ldx_pwm_get_channel(DEFAULT_PWM_ALIAS);
|
||||
pwm_freq = DEFAULT_PWM_FREQUENCY;
|
||||
} else if (argc == 4) {
|
||||
pwm_chip = parse_argument(argv[1], ARG_PWM_CHIP);
|
||||
pwm_channel = parse_argument(argv[2], ARG_PWM_CHANNEL);
|
||||
pwm_freq = atoi(argv[3]);
|
||||
} else {
|
||||
usage_and_exit(name, EXIT_FAILURE);
|
||||
}
|
||||
|
||||
pwm_chip = parse_argument(argv[1]);
|
||||
pwm_freq = atoi(argv[2]);
|
||||
|
||||
if (pwm_chip < 0) {
|
||||
printf("Unable to parse PWM chip\n");
|
||||
if (pwm_chip < 0 || pwm_channel < 0 ) {
|
||||
printf("Unable to parse PWM chip or channel\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
|
@ -136,7 +158,7 @@ int main(int argc, char **argv)
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
pwm_line = ldx_pwm_request(pwm_chip, DEFAULT_PWM_CHANNEL, REQUEST_SHARED);
|
||||
pwm_line = ldx_pwm_request(pwm_chip, pwm_channel, REQUEST_SHARED);
|
||||
|
||||
/* Check PWM. */
|
||||
if (!pwm_line) {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,13 @@ The SPI connections for the sample depends on the running platform:
|
|||
- SPI-1 MISO: Pin 3
|
||||
- SPI-1 MOSI: Pin 4
|
||||
- SPI-1 SS0: Pin 5
|
||||
|
||||
- **CCIMX6Plus SBC**: SPI connector of the board.
|
||||
- VCC: Pin 1
|
||||
- GND: Pin 8
|
||||
- SPI-1 CLK: Pin 2
|
||||
- SPI-1 MISO: Pin 3
|
||||
- SPI-1 MOSI: Pin 4
|
||||
- SPI-1 SS0: Pin 5
|
||||
- **CCIMX6UL SBC Express**: Expansion connector of the board.
|
||||
- VCC: Pin 17
|
||||
- GND: Pin 20
|
||||
|
|
@ -22,7 +28,6 @@ The SPI connections for the sample depends on the running platform:
|
|||
- SPI-3 MISO: Pin 21
|
||||
- SPI-3 MOSI: Pin 19
|
||||
- SPI-3 SS0: Pin 24
|
||||
|
||||
- **CCIMX6UL SBC Pro**: SPI connector of the board.
|
||||
- VCC: Pin 1
|
||||
- GND: Pin 8
|
||||
|
|
@ -31,65 +36,33 @@ The SPI connections for the sample depends on the running platform:
|
|||
- SPI-1 MOSI: Pin 4
|
||||
- SPI-1 SS0: Pin 5
|
||||
|
||||
The following device tree modifications are required for the sample to work:
|
||||
- **CCIMX6 SBC**:
|
||||
```
|
||||
&ecspi1 {
|
||||
status = "okay";
|
||||
|
||||
spidev@0 {
|
||||
reg = <0>;
|
||||
compatible = "spidev";
|
||||
spi-max-frequency = <1000000>;
|
||||
status = "okay";
|
||||
};
|
||||
};
|
||||
```
|
||||
- **CCIMX6UL SBC Express**:
|
||||
```
|
||||
&ecspi3 {
|
||||
status = "okay";
|
||||
|
||||
spidev@0 {
|
||||
reg = <0>;
|
||||
compatible = "spidev";
|
||||
spi-max-frequency = <1000000>;
|
||||
status = "okay";
|
||||
};
|
||||
};
|
||||
```
|
||||
- **CCIMX6UL SBC Pro**:
|
||||
```
|
||||
&ecspi1 {
|
||||
status = "okay";
|
||||
|
||||
spidev@0 {
|
||||
reg = <0>;
|
||||
compatible = "spidev";
|
||||
spi-max-frequency = <1000000>;
|
||||
status = "okay";
|
||||
};
|
||||
};
|
||||
```
|
||||
|
||||
Running the application
|
||||
-----------------------
|
||||
Before launching the application you need to enable the SPI module with the
|
||||
following command:
|
||||
|
||||
```
|
||||
# modprobe spidev
|
||||
```
|
||||
Once the binary is in the target,launch the application:
|
||||
|
||||
```
|
||||
root@ccimx6ulstarter:~# ./apix-spi-example
|
||||
# ./apix-spi-example
|
||||
Example application using libdigiapix SPI support
|
||||
|
||||
Usage: apix-spi-example <spi-dev> <spi-ss> <address-size> <page-size> <page-index>
|
||||
|
||||
<spi-dev> SPI device index to use
|
||||
<spi-ss> SPI slave index to use
|
||||
<spi-dev> SPI device index to use or alias
|
||||
<spi-ss> SPI slave index to use or alias
|
||||
<address-size> Number of EEPROM memory address bytes
|
||||
<page-size> EEPROM memory page size in bytes
|
||||
<page-index> EEPROM memory page index to use
|
||||
|
||||
Aliases for SPI can be configured in the library config file
|
||||
```
|
||||
If no arguments are provided, the example will use the default values:
|
||||
- For the interfaces, default values are configured in "/etc/libdigiapix.conf"
|
||||
- Specific application default values are defined in the main file.
|
||||
|
||||
Compiling the application
|
||||
-------------------------
|
||||
|
|
|
|||
|
|
@ -26,6 +26,11 @@
|
|||
|
||||
#include <libdigiapix/spi.h>
|
||||
|
||||
#define DEFAULT_SPI_ALIAS "DEFAULT_SPI"
|
||||
#define DEFAULT_SPI_ADDRESS_SIZE 1
|
||||
#define DEFAULT_SPI_PAGE_SIZE 16
|
||||
#define DEFAULT_SPI_PAGE_INDEX 0
|
||||
|
||||
#define ARG_SPI_DEVICE 0
|
||||
#define ARG_SPI_SLAVE 1
|
||||
|
||||
|
|
@ -63,8 +68,8 @@ static void usage_and_exit(char *name, int exitval)
|
|||
"Example application using libdigiapix SPI support\n"
|
||||
"\n"
|
||||
"Usage: %s <spi-dev> <spi-ss> <address-size> <page-size> <page-index>\n\n"
|
||||
"<spi-dev> SPI device index to use\n"
|
||||
"<spi-ss> SPI slave index to use\n"
|
||||
"<spi-dev> SPI device index to use or alias\n"
|
||||
"<spi-ss> SPI slave index to use or alias\n"
|
||||
"<address-size> Number of EEPROM memory address bytes\n"
|
||||
"<page-size> EEPROM memory page size in bytes\n"
|
||||
"<page-index> EEPROM memory page index to use\n"
|
||||
|
|
@ -308,20 +313,29 @@ static int read_page(int page_index, uint8_t* data)
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int spi_device, spi_slave, page_index, i = 0;
|
||||
int spi_device = 0, spi_slave = 0, page_index = 0, i = 0;
|
||||
spi_transfer_cfg_t transfer_mode = {0};
|
||||
char *name = basename(argv[0]);
|
||||
|
||||
/* Check input parameters */
|
||||
if (argc != 6)
|
||||
usage_and_exit(name, EXIT_FAILURE);
|
||||
|
||||
if (argc == 1) {
|
||||
/* Use default values */
|
||||
spi_device = ldx_spi_get_device(DEFAULT_SPI_ALIAS);
|
||||
spi_slave = ldx_spi_get_slave(DEFAULT_SPI_ALIAS);
|
||||
address_bytes = DEFAULT_SPI_ADDRESS_SIZE;
|
||||
page_size = DEFAULT_SPI_PAGE_SIZE;
|
||||
page_index = DEFAULT_SPI_PAGE_INDEX;
|
||||
} else if (argc == 6) {
|
||||
/* Parse command line arguments */
|
||||
spi_device = parse_argument(argv[1], ARG_SPI_DEVICE);
|
||||
spi_slave = parse_argument(argv[2], ARG_SPI_SLAVE);
|
||||
address_bytes = atoi(argv[3]);
|
||||
page_size = atoi(argv[4]);
|
||||
page_index = atoi(argv[5]);
|
||||
} else {
|
||||
usage_and_exit(name, EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (spi_device < 0 || spi_slave < 0) {
|
||||
printf("Unable to parse SPI device/slave arguments\n");
|
||||
return EXIT_FAILURE;
|
||||
|
|
|
|||
Loading…
Reference in New Issue