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)
|
LDLIBS += $(shell pkg-config --libs libdigiapix)
|
||||||
|
|
||||||
$(BINARY): main.o
|
$(BINARY): main.o
|
||||||
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@ -lm
|
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $@
|
||||||
|
|
||||||
.PHONY: install
|
.PHONY: install
|
||||||
install: $(BINARY)
|
install: $(BINARY)
|
||||||
|
|
|
||||||
|
|
@ -3,66 +3,37 @@ Digi APIX ADC Sample Application
|
||||||
|
|
||||||
Sample application to access and manage ADC channels using the Digi APIX library.
|
Sample application to access and manage ADC channels using the Digi APIX library.
|
||||||
|
|
||||||
The application enables one ADC channel on the board. After that, the application
|
The application enables one ADC channel on the board. After that, the application
|
||||||
takes periodic samples and prints the raw value and the value in mv.
|
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:
|
The ADC lines used in the sample are mapped as follows in the Digi Boards:
|
||||||
- **CCIMX6 SBC**: PMIC_ADCIN1 (GPIO Connector Pin 1).
|
- **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 Express**: ADC1_IN4 (Expansion Connector Pin 7).
|
||||||
- **CCIMX6UL SBC Pro**: ADC1_IN2 (GPIO Connector Pin 13).
|
- **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
|
Running the application
|
||||||
-----------------------
|
-----------------------
|
||||||
Once the binary is in the target, launch 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.
|
If no arguments are provided, the example will use the default values:
|
||||||
- 'adc_channel' the ADC channel number.
|
- For the interfaces, default values are configured in "/etc/libdigiapix.conf"
|
||||||
- 'interval' is the time interval between samples.
|
- Specific application default values are defined in the main file.
|
||||||
- 'number_of_samples' is the number of samples to take.
|
|
||||||
|
|
||||||
Compiling the application
|
Compiling the application
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <math.h>
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
@ -25,8 +24,12 @@
|
||||||
|
|
||||||
#include "libdigiapix/adc.h"
|
#include "libdigiapix/adc.h"
|
||||||
|
|
||||||
#define ARG_ADC_CHIP 0
|
#define ARG_ADC_CHIP 0
|
||||||
#define ARG_ADC_CHANNEL 1
|
#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;
|
static adc_t *adc;
|
||||||
|
|
||||||
|
|
@ -48,11 +51,12 @@ static void usage_and_exit(char *name, int exitval)
|
||||||
"Example application using libdigiapix ADC support\n"
|
"Example application using libdigiapix ADC support\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Usage: %s <adc_chip> <adc_channel> <interval> <number_of_samples> \n\n"
|
"Usage: %s <adc_chip> <adc_channel> <interval> <number_of_samples> \n\n"
|
||||||
"<adc_chip> ADC chip number\n"
|
"<adc_chip> ADC chip number or alias\n"
|
||||||
"<adc_channel> ADC channel number\n"
|
"<adc_channel> ADC channel number or alias\n"
|
||||||
"<interval> Time interval for sampling\n"
|
"<interval> Time interval for sampling\n"
|
||||||
"<number_of_samples> Number of samples to get\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);
|
"\n", name);
|
||||||
|
|
||||||
exit(exitval);
|
exit(exitval);
|
||||||
|
|
@ -151,23 +155,27 @@ static int adc_sampling_cb(int sample, void *arg)
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
unsigned int channel, chip, interval;
|
int channel = 0, chip = 0, interval = 0, number_of_samples = 0;
|
||||||
int number_of_samples;
|
|
||||||
char *name = basename(argv[0]);
|
char *name = basename(argv[0]);
|
||||||
struct adc_sampling_cb_data cb_data;
|
struct adc_sampling_cb_data cb_data;
|
||||||
|
|
||||||
/* Check input parameters */
|
/* Check input parameters */
|
||||||
if (argc != 5) {
|
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);
|
usage_and_exit(name, EXIT_FAILURE);
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 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]);
|
|
||||||
|
|
||||||
if (chip < 0) {
|
if (chip < 0) {
|
||||||
printf("Invalid chip number\n");
|
printf("Invalid chip number\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
@ -194,7 +202,7 @@ int main(int argc, char *argv[])
|
||||||
atexit(cleanup);
|
atexit(cleanup);
|
||||||
register_signals();
|
register_signals();
|
||||||
|
|
||||||
adc = ldx_adc_request(chip,channel);
|
adc = ldx_adc_request(chip, channel);
|
||||||
|
|
||||||
if (!adc) {
|
if (!adc) {
|
||||||
printf("Failed to initialize ADC\n");
|
printf("Failed to initialize ADC\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
|
one as output (e.g. a user led). The application toggles the output GPIO
|
||||||
whenever an interrupt is generated in the input 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
|
Running the application
|
||||||
-----------------------
|
-----------------------
|
||||||
Once the binary is in the target, launch 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
|
Example application using libdigiapix GPIO support
|
||||||
|
|
||||||
Usage: apix-gpio-example <gpio_in> <gpio_out>
|
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
|
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
|
Compiling the application
|
||||||
-------------------------
|
-------------------------
|
||||||
This example can be compiled using a Digi Embedded Yocto based toolchain. Make
|
This example can be compiled using a Digi Embedded Yocto based toolchain. Make
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,9 @@
|
||||||
|
|
||||||
#include <libdigiapix/gpio.h>
|
#include <libdigiapix/gpio.h>
|
||||||
|
|
||||||
#define TEST_LOOPS 6
|
#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_input;
|
||||||
static gpio_t *gpio_output;
|
static gpio_t *gpio_output;
|
||||||
|
|
@ -152,12 +154,18 @@ int main(int argc, char *argv[])
|
||||||
char *name = basename(argv[0]);
|
char *name = basename(argv[0]);
|
||||||
|
|
||||||
/* Check input parameters */
|
/* Check input parameters */
|
||||||
if (argc != 3)
|
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);
|
usage_and_exit(name, EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
/* Parse command line arguments */
|
|
||||||
button = parse_argument(argv[1]);
|
|
||||||
led = parse_argument(argv[2]);
|
|
||||||
if (button < 0 || led < 0) {
|
if (button < 0 || led < 0) {
|
||||||
printf("Unable to parse button and led GPIOs\n");
|
printf("Unable to parse button and led GPIOs\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,11 @@ The I2C connections for the sample depend on the running platform:
|
||||||
- GND: Pin 6
|
- GND: Pin 6
|
||||||
- I2C-3 SDA: Pin 2
|
- I2C-3 SDA: Pin 2
|
||||||
- I2C-3 SCL: Pin 1
|
- 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.
|
- **CCIMX6UL SBC Express**: Expansion connector of the board.
|
||||||
- VCC: Pin 1
|
- VCC: Pin 1
|
||||||
- GND: Pin 6
|
- GND: Pin 6
|
||||||
|
|
@ -28,19 +33,22 @@ Running the application
|
||||||
Once the binary is in the target, launch the application:
|
Once the binary is in the target, launch the application:
|
||||||
|
|
||||||
```
|
```
|
||||||
#> apix-i2c-example
|
# ./apix-i2c-example
|
||||||
Example application using libdigiapix I2C support
|
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
|
<i2c-address> Address of the I2C EEPROM memory
|
||||||
<address-size> Number of EEPROM memory address bytes
|
<address-size> Number of EEPROM memory address bytes
|
||||||
<page-size> EEPROM memory page size in bytes
|
<page-size> EEPROM memory page size in bytes
|
||||||
<page-index> EEPROM memory page index to use
|
<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
|
Compiling the application
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,12 @@
|
||||||
|
|
||||||
#define I2C_TIMEOUT 1
|
#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 i2c_t *i2c_bus;
|
||||||
static unsigned int i2c_address;
|
static unsigned int i2c_address;
|
||||||
static int eeprom_page_size, eeprom_addr_size;
|
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"
|
"Example application using libdigiapix I2C support\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Usage: %s <i2c-bus> <i2c-address> <address-size> <page-size> <page-index>\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"
|
"<i2c-address> Address of the I2C EEPROM memory\n"
|
||||||
"<address-size> Number of EEPROM memory address bytes\n"
|
"<address-size> Number of EEPROM memory address bytes\n"
|
||||||
"<page-size> EEPROM memory page size in bytes\n"
|
"<page-size> EEPROM memory page size in bytes\n"
|
||||||
|
|
@ -221,22 +227,29 @@ static int read_page(int page_index, uint8_t *data)
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *name = basename(argv[0]);
|
char *name = basename(argv[0]);
|
||||||
int page_index;
|
int page_index = 0;
|
||||||
int i2c_bus_nb;
|
int i2c_bus_nb = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Check input parameters */
|
/* Check input parameters */
|
||||||
if (argc != 6) {
|
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);
|
usage_and_exit(name, EXIT_FAILURE);
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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]);
|
|
||||||
|
|
||||||
if (eeprom_addr_size <= 0) {
|
if (eeprom_addr_size <= 0) {
|
||||||
printf("Address size must be greater than 0\n");
|
printf("Address size must be greater than 0\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
|
||||||
|
|
@ -3,78 +3,36 @@ Digi APIX PWM Sample Application
|
||||||
|
|
||||||
Sample application to access and manage PWM lines using the Digi APIX library.
|
Sample application to access and manage PWM lines using the Digi APIX library.
|
||||||
|
|
||||||
The application enables one PWM line of the board using a frequency of
|
The application enables one PWM line of the board using a frequency of
|
||||||
1000Hz. Then, progressively modifies the duty cycle in a loop from 10% to
|
1000Hz. Then, progressively modifies the duty cycle in a loop from 10% to
|
||||||
90% and vice-versa.
|
90% and vice-versa.
|
||||||
|
|
||||||
The PWM lines used in the sample are mapped as follows in the Digi Boards:
|
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.
|
- **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 Express**: PWM1 - Pin **27** of the expansion connector.
|
||||||
- **CCIMX6UL SBC Pro**: PWM4 - Pin **11** of the GPIO 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
|
Running the application
|
||||||
-----------------------
|
-----------------------
|
||||||
Once the binary is in the target, launch 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
|
If no arguments are provided, the example will use the default values:
|
||||||
PWM chip (0 by default) and a frequency of 1000Hz. If a different PWM chip or frequency
|
- For the interfaces, default values are configured in "/etc/libdigiapix.conf"
|
||||||
is required, the application allows 2 additional parameters in order to customize
|
- Specific application default values are defined in the main file.
|
||||||
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).
|
|
||||||
|
|
||||||
Compiling the application
|
Compiling the application
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,12 @@
|
||||||
|
|
||||||
#include <libdigiapix/pwm.h>
|
#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 pwm_t *pwm_line;
|
||||||
static int running = 1;
|
static int running = 1;
|
||||||
|
|
@ -43,7 +48,11 @@ static void usage_and_exit(char *name, int exitval)
|
||||||
"\n"
|
"\n"
|
||||||
"Usage: %s <pwm-chip> <pwm-freq>\n\n"
|
"Usage: %s <pwm-chip> <pwm-freq>\n\n"
|
||||||
"<pwm-chip> PWM chip number or alias\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);
|
exit(exitval);
|
||||||
}
|
}
|
||||||
|
|
@ -92,10 +101,11 @@ static void register_signals(void)
|
||||||
* corresponding integer value
|
* corresponding integer value
|
||||||
*
|
*
|
||||||
* @argv: Argument to parse in string format.
|
* @argv: Argument to parse in string format.
|
||||||
|
* @arg_type: Type of the argument to parse.
|
||||||
*
|
*
|
||||||
* Return: The parsed integer argument, -1 on error.
|
* 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;
|
char *endptr;
|
||||||
long value;
|
long value;
|
||||||
|
|
@ -107,27 +117,39 @@ static int parse_argument(char *argv)
|
||||||
|| (errno != 0 && value == 0))
|
|| (errno != 0 && value == 0))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (endptr == argv)
|
if (endptr == argv){
|
||||||
return ldx_pwm_get_channel(endptr);
|
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;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
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]);
|
char *name = basename(argv[0]);
|
||||||
unsigned int pwm_chip, pwm_freq = 0;
|
|
||||||
|
|
||||||
/* Check if the PWM values are passed in the command line. */
|
/* 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);
|
usage_and_exit(name, EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
pwm_chip = parse_argument(argv[1]);
|
if (pwm_chip < 0 || pwm_channel < 0 ) {
|
||||||
pwm_freq = atoi(argv[2]);
|
printf("Unable to parse PWM chip or channel\n");
|
||||||
|
|
||||||
if (pwm_chip < 0) {
|
|
||||||
printf("Unable to parse PWM chip\n");
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -136,7 +158,7 @@ int main(int argc, char **argv)
|
||||||
return EXIT_FAILURE;
|
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. */
|
/* Check PWM. */
|
||||||
if (!pwm_line) {
|
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 MISO: Pin 3
|
||||||
- SPI-1 MOSI: Pin 4
|
- SPI-1 MOSI: Pin 4
|
||||||
- SPI-1 SS0: Pin 5
|
- 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.
|
- **CCIMX6UL SBC Express**: Expansion connector of the board.
|
||||||
- VCC: Pin 17
|
- VCC: Pin 17
|
||||||
- GND: Pin 20
|
- 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 MISO: Pin 21
|
||||||
- SPI-3 MOSI: Pin 19
|
- SPI-3 MOSI: Pin 19
|
||||||
- SPI-3 SS0: Pin 24
|
- SPI-3 SS0: Pin 24
|
||||||
|
|
||||||
- **CCIMX6UL SBC Pro**: SPI connector of the board.
|
- **CCIMX6UL SBC Pro**: SPI connector of the board.
|
||||||
- VCC: Pin 1
|
- VCC: Pin 1
|
||||||
- GND: Pin 8
|
- 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 MOSI: Pin 4
|
||||||
- SPI-1 SS0: Pin 5
|
- 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
|
Running the application
|
||||||
-----------------------
|
-----------------------
|
||||||
Once the binary is in the target, launch the application:
|
Before launching the application you need to enable the SPI module with the
|
||||||
|
following command:
|
||||||
|
|
||||||
```
|
```
|
||||||
root@ccimx6ulstarter:~# ./apix-spi-example
|
# modprobe spidev
|
||||||
|
```
|
||||||
|
Once the binary is in the target,launch the application:
|
||||||
|
|
||||||
|
```
|
||||||
|
# ./apix-spi-example
|
||||||
Example application using libdigiapix SPI support
|
Example application using libdigiapix SPI support
|
||||||
|
|
||||||
Usage: apix-spi-example <spi-dev> <spi-ss> <address-size> <page-size> <page-index>
|
Usage: apix-spi-example <spi-dev> <spi-ss> <address-size> <page-size> <page-index>
|
||||||
|
|
||||||
<spi-dev> SPI device index to use
|
<spi-dev> SPI device index to use or alias
|
||||||
<spi-ss> SPI slave index to use
|
<spi-ss> SPI slave index to use or alias
|
||||||
<address-size> Number of EEPROM memory address bytes
|
<address-size> Number of EEPROM memory address bytes
|
||||||
<page-size> EEPROM memory page size in bytes
|
<page-size> EEPROM memory page size in bytes
|
||||||
<page-index> EEPROM memory page index to use
|
<page-index> EEPROM memory page index to use
|
||||||
|
|
||||||
Aliases for SPI can be configured in the library config file
|
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
|
Compiling the application
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,11 @@
|
||||||
|
|
||||||
#include <libdigiapix/spi.h>
|
#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_DEVICE 0
|
||||||
#define ARG_SPI_SLAVE 1
|
#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"
|
"Example application using libdigiapix SPI support\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Usage: %s <spi-dev> <spi-ss> <address-size> <page-size> <page-index>\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-dev> SPI device index to use or alias\n"
|
||||||
"<spi-ss> SPI slave index to use\n"
|
"<spi-ss> SPI slave index to use or alias\n"
|
||||||
"<address-size> Number of EEPROM memory address bytes\n"
|
"<address-size> Number of EEPROM memory address bytes\n"
|
||||||
"<page-size> EEPROM memory page size in bytes\n"
|
"<page-size> EEPROM memory page size in bytes\n"
|
||||||
"<page-index> EEPROM memory page index to use\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 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};
|
spi_transfer_cfg_t transfer_mode = {0};
|
||||||
char *name = basename(argv[0]);
|
char *name = basename(argv[0]);
|
||||||
|
|
||||||
/* Check input parameters */
|
/* Check input parameters */
|
||||||
if (argc != 6)
|
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);
|
usage_and_exit(name, EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
/* 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]);
|
|
||||||
if (spi_device < 0 || spi_slave < 0) {
|
if (spi_device < 0 || spi_slave < 0) {
|
||||||
printf("Unable to parse SPI device/slave arguments\n");
|
printf("Unable to parse SPI device/slave arguments\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue