2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
23 #include "peripheral_io.h"
43 int read_int_input(int *input)
48 rv = read(0, buf, BUFFER_LEN);
50 /* Ignore Enter without value */
51 if (*buf == '\n' || *buf == '\r') {
52 printf("No input value\n");
56 if (rv < 0) return -1;
62 int gpio_led_test(void)
66 peripheral_gpio_h handle = NULL;
68 printf(" %s()\n", __func__);
69 printf("Enter GPIO pin number ");
71 if (scanf("%d", &num) < 0)
73 printf("num %d\n", num);
75 if ((ret = peripheral_gpio_open(num, &handle)) < PERIPHERAL_ERROR_NONE) {
76 printf("Failed to open\n");
80 if ((ret = peripheral_gpio_set_direction(handle, PERIPHERAL_GPIO_DIRECTION_OUT)) < PERIPHERAL_ERROR_NONE) {
81 printf("Failed to set direction!!\n");
86 printf("Writing..\n");
87 peripheral_gpio_write(handle, 1);
89 peripheral_gpio_write(handle, 0);
92 printf("Write finish\n");
93 if ((ret = peripheral_gpio_close(handle)) < PERIPHERAL_ERROR_NONE) {
94 printf("Failed to close the pin\n");
101 peripheral_gpio_close(handle);
105 void gpio_irq_test_isr(void *user_data)
108 peripheral_gpio_h gpio = user_data;
110 peripheral_gpio_get_pin(gpio, &pin);
112 printf("%s: GPIO %d interrupt occurs.\n", __func__, pin);
115 int gpio_irq_register(void)
117 peripheral_gpio_h gpio = NULL;
120 printf(" %s()\n", __func__);
121 printf("Enter gpio pin number\n");
123 if (read_int_input(&pin) < 0)
126 if ((ret = peripheral_gpio_open(pin, &gpio)) < 0) {
127 printf(">>>>> Failed to open GPIO pin, ret : %d\n", ret);
130 gpio_list = g_list_append(gpio_list, gpio);
132 if ((ret = peripheral_gpio_set_direction(gpio, PERIPHERAL_GPIO_DIRECTION_IN)) < 0) {
133 printf(">>>>> Failed to set direction, ret : %d\n", ret);
136 peripheral_gpio_set_edge_mode(gpio, PERIPHERAL_GPIO_EDGE_BOTH);
137 peripheral_gpio_register_cb(gpio, gpio_irq_test_isr, gpio);
142 gpio_list = g_list_remove(gpio_list, gpio);
143 peripheral_gpio_close(gpio);
147 int gpio_irq_unregister(void)
149 peripheral_gpio_h gpio;
151 int gpio_test_get_handle_by_pin(int pin, peripheral_gpio_h *gpio);
153 printf(" %s()\n", __func__);
154 printf("Enter gpio pin number\n");
156 if (read_int_input(&pin) < 0)
159 if (gpio_test_get_handle_by_pin(pin, &gpio) < 0) {
160 printf(">>>>> cannot find handle. please open the gpio pin.\n");
164 if ((ret = peripheral_gpio_unregister_cb(gpio)) < 0) {
165 printf(">>>>> failed to unregister callback function, ret : %d\n", ret);
169 gpio_list = g_list_remove(gpio_list, gpio);
170 peripheral_gpio_close(gpio);
175 /* Address of GY30 light sensor */
176 #define GY30_ADDR 0x23
178 /* Start measurement at 11x resolution. Measurement time is approx 120ms. */
179 #define GY30_CONT_HIGH_RES_MODE 0x10
181 #define GY30_READ_INTENSITY(buf) ((buf[0] << 8 | buf[1]) / 1.2)
183 int i2c_gy30_test(void)
187 unsigned char buf[10];
188 peripheral_i2c_h i2c;
190 printf(" %s()\n", __func__);
191 printf("Enter I2C bus number\n");
193 if (read_int_input(&bus_num) < 0)
196 if ((ret = peripheral_i2c_open(bus_num, GY30_ADDR, &i2c)) < 0) {
197 printf("Failed to open I2C communication, ret : %d\n", ret);
201 if ((ret = peripheral_i2c_write_byte(i2c, GY30_CONT_HIGH_RES_MODE)) < 0) {
202 printf("Failed to write, ret : %d\n", ret);
209 ret = peripheral_i2c_read(i2c, buf, 2);
211 printf("Failed to read, ret : %d\n", ret);
212 result = GY30_READ_INTENSITY(buf);
213 printf("Light intensity : %d\n", result);
216 peripheral_i2c_close(i2c);
220 peripheral_i2c_close(i2c);
224 #define MMA7455_ADDRESS 0x1D //I2C Address for the sensor
226 #define MMA7455_MCTL 0x16 // Mode Control
228 #define MMA7455_MCTL_STANDBY_MODE 0x0
229 #define MMA7455_MCTL_MEASUREMENT_MODE 0x01
230 #define MMA7455_MCTL_LEVEL_DETECTION_MODE 0x02
231 #define MMA7455_MCTL_PULSE_DETECTION_MODE 0x03
232 #define MMA7455_MCTL_2G 0x04 //Set Sensitivity to 2g
233 #define MMA7455_MCTL_4G 0x08 //Set Sensitivity to 4g
234 #define MMA7455_MCTL_8G 0x00 //Set Sensitivity to 8g
236 #define MMA7455_INTRST 0x17
238 #define MMA7455_CONTROL1 0x18
239 #define MMA7455_CONTROL1_INTREG 0x06
240 #define MMA7455_CONTROL1_DFBW 0x80
242 #define MMA7455_XOUT8 0x06 //Register for reading the X-Axis
243 #define MMA7455_YOUT8 0x07 //Register for reading the Y-Axis
244 #define MMA7455_ZOUT8 0x08 //Register for reading the Z-Axis
246 static void i2c_mma7455_isr(void *user_data)
248 peripheral_i2c_h i2c = user_data;
249 int x_pos, y_pos, z_pos;
252 peripheral_i2c_write_byte(i2c, MMA7455_XOUT8);
253 peripheral_i2c_read_byte(i2c, buf);
256 peripheral_i2c_write_byte(i2c, MMA7455_YOUT8);
257 peripheral_i2c_read_byte(i2c, buf);
260 peripheral_i2c_write_byte(i2c, MMA7455_ZOUT8);
261 peripheral_i2c_read_byte(i2c, buf);
264 printf("Result X : %d, Y : %d, Z : %d\n", x_pos, y_pos, z_pos);
266 /* Reset interrupt flags */
267 buf[0] = MMA7455_INTRST;
269 peripheral_i2c_write(i2c, buf, 2);
271 peripheral_i2c_write(i2c, buf, 2);
276 int i2c_mma7455_test(void)
278 static peripheral_i2c_h i2c;
279 static peripheral_gpio_h isr_gpio;
280 unsigned char buf[4];
281 int bus_num, gpio_num, ret;
284 printf(" %s()\n", __func__);
286 printf("Disabling the test\n");
288 peripheral_i2c_close(i2c);
290 printf("i2c(bus = %d address = %d) handle is closed\n", bus_num, MMA7455_ADDRESS);
293 peripheral_gpio_close(isr_gpio);
295 printf("isr_gpio handle is closed\n");
301 printf("Enter I2C bus number\n");
303 if (read_int_input(&bus_num) < 0)
306 if ((ret = peripheral_i2c_open(bus_num, MMA7455_ADDRESS, &i2c)) < 0) {
307 printf(">>>>> Failed to open I2C communication, ret : %d \n", ret);
311 buf[0] = MMA7455_MCTL;
312 buf[1] = MMA7455_MCTL_8G | MMA7455_MCTL_PULSE_DETECTION_MODE;
313 if ((ret = peripheral_i2c_write(i2c, buf, 2)) != 0) {
314 printf(">>>>> Failed to write, ret : %d\n", ret);
318 printf("Enter GPIO pin number for Interrupt\n");
319 if (read_int_input(&gpio_num) < 0)
322 if ((gpio_num > 0) && (peripheral_gpio_open(gpio_num, &isr_gpio) == 0)) {
323 ret = peripheral_gpio_set_direction(isr_gpio, PERIPHERAL_GPIO_DIRECTION_IN);
325 printf(">>>> Failed to set direction of isr_gpio\n");
327 ret = peripheral_gpio_set_edge_mode(isr_gpio, PERIPHERAL_GPIO_EDGE_RISING);
329 printf(">>>> Failed to set edge mode of isr_gpio\n");
331 ret = peripheral_gpio_register_cb(isr_gpio, i2c_mma7455_isr, (void*)i2c);
333 printf(">>>> Failed to register gpio callback\n");
335 buf[0] = MMA7455_INTRST;
337 peripheral_i2c_write(i2c, buf, 2);
339 peripheral_i2c_write(i2c, buf, 2);
341 printf("callback is registered on gpio pin %d\n", gpio_num);
342 printf("i2c(bus = %d address = %d) handle is open\n", bus_num, MMA7455_ADDRESS);
345 int x_pos, y_pos, z_pos;
348 peripheral_i2c_write_byte(i2c, MMA7455_XOUT8);
349 peripheral_i2c_read_byte(i2c, buf);
352 peripheral_i2c_write_byte(i2c, MMA7455_YOUT8);
353 peripheral_i2c_read_byte(i2c, buf);
356 peripheral_i2c_write_byte(i2c, MMA7455_ZOUT8);
357 peripheral_i2c_read_byte(i2c, buf);
360 printf("Result X : %d, Y : %d, Z : %d\n", x_pos, y_pos, z_pos);
362 peripheral_i2c_close(i2c);
364 printf("i2c(bus = %d address = %d) handle is closed\n", bus_num, MMA7455_ADDRESS);
369 peripheral_i2c_close(i2c);
374 int pwm_test_led(void)
376 int device = 0, channel = 0;
377 int period = 1 * 1000;
378 int duty_cycle = 1 * 1000 / 100;
382 int get_period, get_duty_cycle;
383 peripheral_pwm_h dev;
385 printf(" %s()\n", __func__);
387 peripheral_pwm_open(device, channel, &dev);
388 peripheral_pwm_set_period(dev, period); /* period: nanosecond */
389 peripheral_pwm_set_duty_cycle(dev, duty_cycle); /* duty_cycle: nanosecond */
390 peripheral_pwm_set_enable(dev, 1); /* 0: disable, 1: enable */
393 for (set_duty_cycle = period; set_duty_cycle > 0; set_duty_cycle -= 50) {
395 peripheral_pwm_set_duty_cycle(dev, set_duty_cycle);
396 peripheral_pwm_get_period(dev, &get_period);
397 peripheral_pwm_get_duty_cycle(dev, &get_duty_cycle);
398 printf("period(%d), duty_cycle(%d)\n", get_period, get_duty_cycle);
401 for (set_duty_cycle = 0; set_duty_cycle < period; set_duty_cycle += 50) {
403 peripheral_pwm_set_duty_cycle(dev, set_duty_cycle);
404 peripheral_pwm_get_period(dev, &get_period);
405 peripheral_pwm_get_duty_cycle(dev, &get_duty_cycle);
406 printf("period(%d), duty_cycle(%d)\n", get_period, get_duty_cycle);
411 peripheral_pwm_set_enable(dev, 0); /* 0: disable, 1: enable */
412 peripheral_pwm_close(dev);
417 int pwm_test_motor(void)
419 int device = 0, channel = 0;
420 int period = 20000000;
421 int duty_cycle = 1500000;
422 int cnt = 0, idx = 0;
423 int degree[3] = {0, 45, 90};
424 peripheral_pwm_h dev;
426 printf(" %s()\n", __func__);
428 peripheral_pwm_open(device, channel, &dev);
429 for (cnt = 0; cnt < 5; cnt++) {
430 for (idx = 0; idx < 3; idx++) {
431 switch (degree[idx]) {
433 duty_cycle = 1000000;
436 duty_cycle = 1500000;
439 duty_cycle = 2000000;
442 duty_cycle = 2000000;
445 printf("set degree: %d\n", degree[idx]);
446 peripheral_pwm_set_period(dev, period);
447 peripheral_pwm_set_duty_cycle(dev, duty_cycle);
448 peripheral_pwm_set_enable(dev, 1); /* 0: disable, 1: enable */
453 peripheral_pwm_set_enable(dev, 0); /* 0: disable, 1: enable */
454 peripheral_pwm_close(dev);
460 int uart_test_accelerometer(void)
462 peripheral_uart_h uart;
466 unsigned char buf[1024];
468 printf(" %s()\n", __func__);
469 printf("Enter port number");
471 if (scanf("%d", &port) < 0)
474 ret = peripheral_uart_open(port, &uart);
478 ret = peripheral_uart_set_baudrate(uart, PERIPHERAL_UART_BAUDRATE_4800);
482 ret = peripheral_uart_set_mode(uart,
483 PERIPHERAL_UART_BYTESIZE_8BIT,
484 PERIPHERAL_UART_PARITY_NONE,
485 PERIPHERAL_UART_STOPBITS_1BIT);
489 ret = peripheral_uart_set_flowcontrol(uart, true, false);
494 ret = peripheral_uart_flush(uart);
499 ret = peripheral_uart_read(uart, buf, 13);
501 if (ret == PERIPHERAL_ERROR_NO_DATA)
502 printf("No data to read (%d)\n", ret);
504 printf("Failed to read (%d)\n", ret);
512 peripheral_uart_close(uart);
516 peripheral_uart_close(uart);
522 #define MMA7455_MCTL_SPI3W 0x20 // SPI is 3 wire mode
523 #define MMA7455_MCTL_DRPD 0x40 // Data ready status is not output to INT1/DRDY PIN
525 #define MMA7455_SPI_REGISTER_WRITE 0x40
527 int spi_mma7455_module_test(void)
530 int bus_num, cs_num, ret;
531 unsigned char tx_buf[10];
532 unsigned char rx_buf[10];
534 peripheral_spi_h spi;
536 printf(" %s()\n", __func__);
537 printf("Enter SPI bus number : ");
538 if (scanf("%d", &bus_num) < 0)
541 printf("Enter SPI cs number : ");
542 if (scanf("%d", &cs_num) < 0)
545 if ((ret = peripheral_spi_open(bus_num, cs_num, &spi)) < 0) {
546 printf("Failed to open I2C communication, ret : %d\n", ret);
549 peripheral_spi_set_mode(spi, PERIPHERAL_SPI_MODE_0);
550 peripheral_spi_set_lsb_first(spi, false);
551 peripheral_spi_set_bits_per_word(spi, 8);
552 peripheral_spi_set_frequency(spi, 100000);
554 printf("bus : %d, cs : %d, ", bus_num, cs_num);
555 peripheral_spi_get_mode(spi, (peripheral_spi_mode_e*)&num);
556 printf("mode : %d, ", num);
557 peripheral_spi_get_lsb_first(spi, (bool*)&num);
558 printf("lsb first : %d, ", (bool)num);
559 peripheral_spi_get_bits_per_word(spi, (unsigned char*)&num);
560 printf("bits : %d, ", (unsigned char)num);
561 peripheral_spi_get_frequency(spi, &num);
562 printf("max frequency : %d\n", num);
564 tx_buf[0] = (MMA7455_MCTL | MMA7455_SPI_REGISTER_WRITE) << 1;
565 tx_buf[1] = MMA7455_MCTL_DRPD | MMA7455_MCTL_SPI3W | MMA7455_MCTL_2G | MMA7455_MCTL_MEASUREMENT_MODE;
566 if ((ret = peripheral_spi_write(spi, tx_buf, 2)) < 0) {
567 printf("Failed to write, ret : %d\n", ret);
573 unsigned char buf[5];
576 for (i = 0; i < 3; i++) {
577 tx_buf[0] = (MMA7455_XOUT8 + i) << 1;
579 ret = peripheral_spi_read_write(spi, tx_buf, rx_buf, 2);
581 printf("Failed to read, ret : %d\n", ret);
585 printf("X = 0x%02X, Y = 0x%02X, Z = 0x%02X\n", buf[0], buf[1], buf[2]);
588 peripheral_spi_close(spi);
592 peripheral_spi_close(spi);
596 int gpio_test_get_handle_by_pin(int pin, peripheral_gpio_h *gpio)
598 peripheral_gpio_h handle;
604 handle = (peripheral_gpio_h)cursor->data;
605 peripheral_gpio_get_pin(handle, &cur_pin);
608 cursor = g_list_next(cursor);
610 if (!cursor) return -1;
617 int print_gpio_handle(void)
619 peripheral_gpio_h gpio;
621 peripheral_gpio_direction_e direction;
622 peripheral_gpio_edge_e edge;
624 char *dir_str, *edge_str;
626 printf("--- GPIO handle info. -------------------------------------------\n");
627 printf(" No Pin Direction Value Edge mode\n");
631 gpio = (peripheral_gpio_h)cursor->data;
633 if (peripheral_gpio_get_pin(gpio, &pin) < 0)
635 if (peripheral_gpio_get_direction(gpio, &direction) < 0)
637 if (peripheral_gpio_get_edge_mode(gpio, &edge) < 0)
640 if (direction == PERIPHERAL_GPIO_DIRECTION_IN)
642 else if (direction == PERIPHERAL_GPIO_DIRECTION_OUT_LOW)
644 else if (direction == PERIPHERAL_GPIO_DIRECTION_OUT_HIGH)
645 dir_str = "OUT_HIGH";
649 if (edge == PERIPHERAL_GPIO_EDGE_NONE)
651 else if (edge == PERIPHERAL_GPIO_EDGE_RISING)
653 else if (edge == PERIPHERAL_GPIO_EDGE_FALLING)
654 edge_str = "FALLING";
655 else if (edge == PERIPHERAL_GPIO_EDGE_BOTH)
658 edge_str = "UNKNOWN";
660 if (direction == PERIPHERAL_GPIO_DIRECTION_IN) {
661 if (peripheral_gpio_read(gpio, &value) < 0)
663 printf("%8d%8d%12s%8d%12s\n", g_list_position(gpio_list, cursor),
664 pin, dir_str, value, edge_str);
666 printf("%8d%8d%12s%20s\n", g_list_position(gpio_list, cursor),
667 pin, dir_str, edge_str);
669 cursor = g_list_next(cursor);
671 printf("-----------------------------------------------------------------\n");
676 int gpio_test_open(void)
678 peripheral_gpio_h gpio;
681 printf("%s\n", __func__);
682 printf("Enter GPIO pin number\n");
684 if (read_int_input(&pin) < 0)
687 if ((ret = peripheral_gpio_open(pin, &gpio)) < 0) {
688 printf(">>>>> GPIO open failed, ret : %d\n", ret);
691 gpio_list = g_list_append(gpio_list, gpio);
697 int gpio_test_close(void)
699 peripheral_gpio_h gpio;
702 printf("%s\n", __func__);
703 printf("Enter GPIO pin number\n");
705 if (read_int_input(&pin) < 0)
708 if (gpio_test_get_handle_by_pin(pin, &gpio) < 0) {
709 printf(">>>>> Cannot find handle. Please open the GPIO pin\n");
712 gpio_list = g_list_remove(gpio_list, gpio);
714 if ((ret = peripheral_gpio_close(gpio)) < 0) {
715 printf(">>>>> GPIO close failed, ret : %d\n", ret);
723 int gpio_test_set_direction(void)
725 peripheral_gpio_h gpio;
729 printf("%s\n", __func__);
730 printf("Enter gpio pin number\n");
732 if (read_int_input(&pin) < 0)
735 if (gpio_test_get_handle_by_pin(pin, &gpio) < 0) {
736 printf(">>>>> Cannot find handle. Please open the GPIO pin\n");
740 printf("Enter direction (0:IN, 1:OUT_LOW, 2:OUT_HIGH)\n");
741 if (read_int_input(&direction) < 0)
744 if (direction > PERIPHERAL_GPIO_DIRECTION_OUT_HIGH ||
745 direction < PERIPHERAL_GPIO_DIRECTION_IN) {
746 printf(">>>>> Wrong input value\n");
750 if ((ret = peripheral_gpio_set_direction(gpio, (peripheral_gpio_direction_e)direction)) < 0) {
751 printf(">>>>> Failed to set direction, ret : %d\n", ret);
758 int gpio_test_write(void)
760 peripheral_gpio_h gpio;
764 printf("%s\n", __func__);
765 printf("Enter gpio pin number\n");
767 if (read_int_input(&pin) < 0)
770 if (gpio_test_get_handle_by_pin(pin, &gpio) < 0) {
771 printf(">>>>> Cannot find handle. Please open the GPIO pin\n");
775 printf("Enter value (0:LOW, 1:HIGH)\n");
776 if (read_int_input(&value) < 0)
779 if (value < 0 || value > 1) {
780 printf(">>>>> Wrong input value\n");
784 if ((ret = peripheral_gpio_write(gpio, value)) < 0) {
785 printf(">>>>> Failed to write value, ret : %d\n", ret);
792 int gpio_test_set_edge_mode(void)
794 peripheral_gpio_h gpio;
798 printf("%s\n", __func__);
799 printf("Enter gpio pin number\n");
801 if (read_int_input(&pin) < 0)
804 if (gpio_test_get_handle_by_pin(pin, &gpio) < 0) {
805 printf(">>>>> Cannot find handle. Please open the GPIO pin\n");
809 printf("Enter edge mode (0:NONE, 1:RISING, 2:FALLING, 3:BOTH)\n");
810 if (read_int_input(&edge) < 0)
813 if (edge < PERIPHERAL_GPIO_EDGE_NONE || edge > PERIPHERAL_GPIO_EDGE_BOTH) {
814 printf(">>>>> Wrong input value\n");
818 if ((ret = peripheral_gpio_set_edge_mode(gpio, (peripheral_gpio_edge_e)edge)) < 0) {
819 printf(">>>>> Failed to set edge mode, ret : %d\n", ret);
826 int gpio_test_set_register_cb(void)
828 peripheral_gpio_h gpio;
831 printf("%s\n", __func__);
832 printf("Enter gpio pin number\n");
834 if (read_int_input(&pin) < 0)
837 if (gpio_test_get_handle_by_pin(pin, &gpio) < 0) {
838 printf(">>>>> Cannot find handle. Please open the GPIO pin\n");
842 if ((ret = peripheral_gpio_register_cb(gpio, gpio_irq_test_isr, gpio)) < 0) {
843 printf(">>>>> Failed to register callback function, ret : %d\n", ret);
849 int gpio_test_set_unregister_cb(void)
851 peripheral_gpio_h gpio;
854 printf("%s\n", __func__);
855 printf("Enter gpio pin number\n");
857 if (read_int_input(&pin) < 0)
860 if (gpio_test_get_handle_by_pin(pin, &gpio) < 0) {
861 printf(">>>>> Cannot find handle. Please open the GPIO pin\n");
865 if ((ret = peripheral_gpio_unregister_cb(gpio)) < 0) {
866 printf(">>>>> failed to unregister callback function, ret : %d\n", ret);
873 int enter_main(void);
875 tc_table_t gpio_tc_table[] = {
876 {"Open GPIO pin", 1, gpio_test_open},
877 {"Close GPIO pin", 2, gpio_test_close},
878 {"Set direction GPIO pin", 3, gpio_test_set_direction},
879 {"Write value to GPIO pin", 4, gpio_test_write},
880 {"Set edge mode", 5, gpio_test_set_edge_mode},
881 {"Register callback", 6, gpio_test_set_register_cb},
882 {"Unregister callback", 7, gpio_test_set_unregister_cb},
883 {"Print GPIO handle", 9, print_gpio_handle},
884 {"Go back to main", 0, enter_main},
888 int enter_gpio_test(void)
890 tc_table = gpio_tc_table;
896 int enter_i2c_test(void)
901 int enter_pwm_test(void)
906 int enter_adc_test(void)
911 int enter_uart_test(void)
916 int enter_spi_test(void)
921 tc_table_t preset_tc_table[] = {
922 {"[Preset Test] GPIO LED", 1, gpio_led_test},
923 {"[Preset Test] I2C GY30 Light sensor", 2, i2c_gy30_test},
924 {"[Preset Test] I2C MMA7455 Accel. sensor", 3, i2c_mma7455_test},
925 {"[Preset Test] PWM LED", 4, pwm_test_led},
926 {"[Preset Test] PWM Motor", 5, pwm_test_motor},
927 {"[Preset Test] Uart Accelerometer", 6, uart_test_accelerometer},
928 {"[Preset Test] SPI MMA7455 Accel. sensor", 7, spi_mma7455_module_test},
929 {"[Preset Test] GPIO IRQ register", 8, gpio_irq_register},
930 {"[Preset Test] GPIO IRQ unregister", 9, gpio_irq_unregister},
931 {"Go back to main", 0, enter_main},
935 int enter_preset_test(void)
937 tc_table = preset_tc_table;
941 int terminate_test(void)
945 printf("Terminate test\n");
946 g_main_loop_quit(main_loop);
953 tc_table_t main_tc_table[] = {
954 {"GPIO Test Menu", 1, enter_gpio_test},
955 {"I2C Test Menu", 2, enter_i2c_test},
956 {"PWM Test Menu", 3, enter_pwm_test},
957 {"ADC Test Menu", 4, enter_adc_test},
958 {"UART Test Menu", 5, enter_uart_test},
959 {"SPI Test Menu", 6, enter_spi_test},
960 {"Preset Test", 10, enter_preset_test},
961 {"Exit Test", 0, terminate_test},
967 tc_table = main_tc_table;
972 static int test_input_callback(void *data)
975 long test_id = (long)data;
976 int ret = PERIPHERAL_ERROR_NONE;
981 while (tc[i].tc_name) {
982 if (tc[i].tc_code == test_id && tc[i].tc_func) {
983 ret = tc[i].tc_func();
984 if (ret != PERIPHERAL_ERROR_NONE)
985 printf(">>>>> Test Error Returned !!! : %d\n", ret);
991 if (!tc[i].tc_name) {
992 printf(">>>>> Wrong input value!\n");
999 static void print_tc_usage(void)
1003 printf("===========================================\n");
1004 while (tc_table[i].tc_name) {
1005 printf(" %2d : %s\n", tc_table[i].tc_code, tc_table[i].tc_name);
1008 printf("===========================================\n");
1009 printf("Enter TC number\n");
1012 static gboolean key_event_cb(GIOChannel *chan, GIOCondition cond, gpointer data)
1014 char buf[BUFFER_LEN] = {0,};
1018 memset(buf, 0, sizeof(buf));
1020 rv = read(0, buf, BUFFER_LEN);
1022 if (*buf == '\n' || *buf == '\r') {
1027 if (rv < 0) return FALSE;
1029 test_id = atoi(buf);
1031 test_input_callback((void *)test_id);
1037 int main(int argc, char **argv)
1041 main_loop = g_main_loop_new(NULL, FALSE);
1042 key_io = g_io_channel_unix_new(0);
1044 tc_table = main_tc_table;
1047 g_io_add_watch(key_io, (G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL), key_event_cb, NULL);
1049 g_main_loop_run(main_loop);
1051 g_io_channel_unref(key_io);
1052 g_main_loop_unref(main_loop);