diff --git a/apix-adc-example/Makefile b/apix-adc-example/Makefile index 4176fbe..65d07d1 100644 --- a/apix-adc-example/Makefile +++ b/apix-adc-example/Makefile @@ -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) diff --git a/apix-adc-example/README.md b/apix-adc-example/README.md index a648949..cd24ed9 100644 --- a/apix-adc-example/README.md +++ b/apix-adc-example/README.md @@ -3,66 +3,37 @@ Digi APIX ADC Sample Application 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. 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 number or alias + ADC channel number or alias + Time interval for sampling + 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 ------------------------- diff --git a/apix-adc-example/main.c b/apix-adc-example/main.c index 51feaef..29b535d 100644 --- a/apix-adc-example/main.c +++ b/apix-adc-example/main.c @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -25,8 +24,12 @@ #include "libdigiapix/adc.h" -#define ARG_ADC_CHIP 0 -#define ARG_ADC_CHANNEL 1 +#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; @@ -48,11 +51,12 @@ static void usage_and_exit(char *name, int exitval) "Example application using libdigiapix ADC support\n" "\n" "Usage: %s \n\n" - " ADC chip number\n" - " ADC channel number\n" + " ADC chip number or alias\n" + " ADC channel number or alias\n" " Time interval for sampling\n" " 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,23 +155,27 @@ 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) { + 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); - 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) { printf("Invalid chip number\n"); return EXIT_FAILURE; @@ -194,7 +202,7 @@ int main(int argc, char *argv[]) atexit(cleanup); register_signals(); - adc = ldx_adc_request(chip,channel); + adc = ldx_adc_request(chip, channel); if (!adc) { printf("Failed to initialize ADC\n"); diff --git a/apix-gpio-example/README.md b/apix-gpio-example/README.md index 1ff8d93..b360b5c 100644 --- a/apix-gpio-example/README.md +++ b/apix-gpio-example/README.md @@ -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 @@ -20,6 +34,10 @@ Usage: apix-gpio-example 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 diff --git a/apix-gpio-example/main.c b/apix-gpio-example/main.c index 0062eca..f07dab0 100644 --- a/apix-gpio-example/main.c +++ b/apix-gpio-example/main.c @@ -24,7 +24,9 @@ #include -#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_output; @@ -152,12 +154,18 @@ int main(int argc, char *argv[]) char *name = basename(argv[0]); /* 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); + } - /* Parse command line arguments */ - button = parse_argument(argv[1]); - led = parse_argument(argv[2]); if (button < 0 || led < 0) { printf("Unable to parse button and led GPIOs\n"); return EXIT_FAILURE; diff --git a/apix-i2c-example/README.md b/apix-i2c-example/README.md index c4cd489..9e046d4 100644 --- a/apix-i2c-example/README.md +++ b/apix-i2c-example/README.md @@ -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 +Usage: apix-i2c-example - I2C bus index to use + I2C bus index to use or alias Address of the I2C EEPROM memory Number of EEPROM memory address bytes EEPROM memory page size in bytes 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 ------------------------- diff --git a/apix-i2c-example/main.c b/apix-i2c-example/main.c index d5a2217..336ec33 100644 --- a/apix-i2c-example/main.c +++ b/apix-i2c-example/main.c @@ -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 \n\n" - " I2C bus index to use\n" + " I2C bus index to use or alias\n" " Address of the I2C EEPROM memory\n" " Number of EEPROM memory address bytes\n" " 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) { 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) { + 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); - 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) { printf("Address size must be greater than 0\n"); return EXIT_FAILURE; diff --git a/apix-pwm-example/README.md b/apix-pwm-example/README.md index 5630927..e43762a 100644 --- a/apix-pwm-example/README.md +++ b/apix-pwm-example/README.md @@ -3,78 +3,36 @@ Digi APIX PWM Sample Application 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 -1000Hz. Then, progressively modifies the duty cycle in a loop from 10% to +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 90% and vice-versa. 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 number or alias + PWM channel number or alias + 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 ------------------------- diff --git a/apix-pwm-example/main.c b/apix-pwm-example/main.c index d57c43f..ef50bc6 100644 --- a/apix-pwm-example/main.c +++ b/apix-pwm-example/main.c @@ -24,7 +24,12 @@ #include -#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 \n\n" " PWM chip number or alias\n" - " Frequency to use (Hz)\n\n", name); + " PWM channel number or alias\n" + " 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) - return ldx_pwm_get_channel(endptr); - + 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) { diff --git a/apix-spi-example/README.md b/apix-spi-example/README.md index 8941e67..e14d475 100644 --- a/apix-spi-example/README.md +++ b/apix-spi-example/README.md @@ -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 ----------------------- -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 Usage: apix-spi-example - SPI device index to use - SPI slave index to use + SPI device index to use or alias + SPI slave index to use or alias Number of EEPROM memory address bytes EEPROM memory page size in bytes 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 ------------------------- diff --git a/apix-spi-example/main.c b/apix-spi-example/main.c index bd70ae6..9b4c313 100644 --- a/apix-spi-example/main.c +++ b/apix-spi-example/main.c @@ -26,6 +26,11 @@ #include +#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 \n\n" - " SPI device index to use\n" - " SPI slave index to use\n" + " SPI device index to use or alias\n" + " SPI slave index to use or alias\n" " Number of EEPROM memory address bytes\n" " EEPROM memory page size in bytes\n" " 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) + 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); + } - /* 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) { printf("Unable to parse SPI device/slave arguments\n"); return EXIT_FAILURE;