tigp tests
authorNathael Pajani <nathael.pajani@ed3l.fr>
Thu, 3 Jan 2019 22:58:44 +0000 (23:58 +0100)
committerNathael Pajani <nathael.pajani@ed3l.fr>
Mon, 6 Feb 2023 01:09:25 +0000 (02:09 +0100)
tests/Makefile [new file with mode: 0644]
tests/main.c [new file with mode: 0644]

diff --git a/tests/Makefile b/tests/Makefile
new file mode 100644 (file)
index 0000000..41ae555
--- /dev/null
@@ -0,0 +1,21 @@
+# Makefile for apps
+
+MODULE = $(shell basename $(shell cd .. && pwd && cd -))
+NAME = $(shell basename $(CURDIR))
+
+# Add this to your ~/.vimrc in order to get proper function of :make in vim :
+# let $COMPILE_FROM_IDE = 1
+ifeq ($(strip $(COMPILE_FROM_IDE)),)
+       PRINT_DIRECTORY = --no-print-directory
+else
+       PRINT_DIRECTORY =
+       LANG = C
+endif
+
+.PHONY: $(NAME).bin
+$(NAME).bin:
+       @make -C ../../.. ${PRINT_DIRECTORY} NAME=$(NAME) MODULE=$(MODULE) apps/$(MODULE)/$(NAME)/$@
+
+clean mrproper:
+       @make -C ../../.. ${PRINT_DIRECTORY} $@
+
diff --git a/tests/main.c b/tests/main.c
new file mode 100644 (file)
index 0000000..245ca29
--- /dev/null
@@ -0,0 +1,249 @@
+/****************************************************************************
+ *   oled/main.c
+ *
+ * Test of Oled display on tigp board
+ *
+ * Copyright 2017 Nathael Pajani <nathael.pajani@ed3l.fr>
+ *
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ *************************************************************************** */
+
+
+
+#include "core/system.h"
+#include "core/systick.h"
+#include "core/pio.h"
+#include "lib/stdio.h"
+#include "drivers/serial.h"
+#include "drivers/gpio.h"
+#include "drivers/ssp.h"
+
+#include "extdrv/status_led.h"
+#include "extdrv/ssd130x_oled_driver.h"
+#include "extdrv/ssd130x_oled_buffer.h"
+#include "lib/font.h"
+
+#include "extdrv/ws2812.h"
+
+
+#define MODULE_VERSION    0x01
+#define MODULE_NAME "TIGP"
+
+#define TEST_VERSION   "03"
+
+#define SELECTED_FREQ  FREQ_SEL_48MHz
+
+
+/***************************************************************************** */
+/* Pins configuration */
+/* pins blocks are passed to set_pins() for pins configuration.
+ * Unused pin blocks can be removed safely with the corresponding set_pins() call
+ * All pins blocks may be safelly merged in a single block for single set_pins() call..
+ */
+const struct pio_config common_pins[] = {
+       /* UART 0 : Config / Debug / USB */
+       { LPC_UART0_RX_PIO_0_1,  LPC_IO_DIGITAL },
+       { LPC_UART0_TX_PIO_0_2,  LPC_IO_DIGITAL },
+       /* I2C : RTC, Temp sensor, Accelerometer */
+       { LPC_I2C0_SCL_PIO_0_10, (LPC_IO_DIGITAL | LPC_IO_OPEN_DRAIN_ENABLE) },
+       { LPC_I2C0_SDA_PIO_0_11, (LPC_IO_DIGITAL | LPC_IO_OPEN_DRAIN_ENABLE) },
+       /* SPI : Display and uSD card */
+       { LPC_SSP0_SCLK_PIO_0_14, LPC_IO_DIGITAL },
+       { LPC_SSP0_MISO_PIO_0_16, LPC_IO_DIGITAL },
+       { LPC_SSP0_MOSI_PIO_0_17, LPC_IO_DIGITAL },
+       /* Buttons */
+       { LPC_GPIO_0_3, LPC_IO_DIGITAL },  /* B1 */
+       { LPC_GPIO_0_4, LPC_IO_DIGITAL },  /* B2 */
+       { LPC_GPIO_0_5, LPC_IO_DIGITAL },  /* B3 */
+       { LPC_GPIO_0_6, LPC_IO_DIGITAL },  /* B4 */
+       { LPC_GPIO_0_7, LPC_IO_DIGITAL },  /* B6 */
+       { LPC_GPIO_0_8, LPC_IO_DIGITAL },  /* B7 */
+       { LPC_GPIO_0_9, LPC_IO_DIGITAL },  /* B8 */
+       { LPC_GPIO_0_12, LPC_IO_DIGITAL }, /* ISP / B5 */
+       /* GPIO */
+       { LPC_GPIO_0_0, LPC_IO_DIGITAL },  /* Clkout / interrupt from RTC */
+       { LPC_GPIO_0_15, LPC_IO_DIGITAL }, /* Buzer */
+       { LPC_GPIO_0_18, LPC_IO_DIGITAL }, /* WS2812B Leds */
+       { LPC_GPIO_0_29, LPC_IO_DIGITAL }, /* Charging state */
+       { LPC_GPIO_1_0, LPC_IO_DIGITAL }, /* SD Card Chip select */
+       { LPC_GPIO_1_1, LPC_IO_DIGITAL }, /* Oled Ctrl */
+       { LPC_GPIO_1_2, LPC_IO_DIGITAL }, /* Oled Chip select */
+       { LPC_GPIO_1_3, LPC_IO_DIGITAL }, /* Oled Reset */
+       /* Debug */
+       /* FIXME : SWDIO and SWCLK on PIO0_25 and PIO0_26 */
+       /* ADC */
+       { LPC_ADC_AD0_PIO_0_30, LPC_IO_ANALOG },  /* ADC0 */
+       { LPC_ADC_AD1_PIO_0_31, LPC_IO_ANALOG },  /* ADC1 */
+       ARRAY_LAST_PIO,
+};
+
+const struct pio status_led_green = LPC_GPIO_0_27;
+const struct pio status_led_red = LPC_GPIO_0_28;
+
+const struct pio ws2812_data_out_pin = LPC_GPIO_0_18;  /* Led control data pin */
+
+
+/***************************************************************************** */
+/* Basic system init and configuration */
+
+void system_init()
+{
+       /* Stop the Watchdog */
+       startup_watchdog_disable(); /* Do it right now, before it gets a chance to break in */
+       system_set_default_power_state();
+       clock_config(SELECTED_FREQ);
+       set_pins(common_pins);
+       gpio_on();
+       status_led_config(&status_led_green, &status_led_red);
+       /* System tick timer MUST be configured and running in order to use the sleeping
+        * functions */
+       systick_timer_on(1); /* 1ms */
+       systick_start();
+}
+
+/* Define our fault handler. This one is not mandatory, the dummy fault handler
+ * will be used when it's not overridden here.
+ * Note : The default one does a simple infinite loop. If the watchdog is deactivated
+ * the system will hang.
+ */
+void fault_info(const char* name, uint32_t len)
+{
+       uprintf(UART0, name);
+       while (1);
+}
+
+
+/***************************************************************************** */
+/* Oled Display */
+static uint8_t gddram[ 4 + GDDRAM_SIZE ];
+struct oled_display display = {
+       .bus_type = SSD130x_BUS_SPI,
+       .bus_num = SSP_BUS_0,
+       .charge_pump = SSD130x_INTERNAL_PUMP,
+       .video_mode = SSD130x_DISP_NORMAL,
+       .contrast = 128,
+       .scan_dir = SSD130x_SCAN_BOTTOM_TOP,
+       .read_dir = SSD130x_RIGHT_TO_LEFT,
+       .display_offset_dir = SSD130x_MOVE_TOP,
+       .display_offset = 4,
+       .gddram = gddram,
+       .gpio_cs = LPC_GPIO_1_2,
+       .gpio_dc = LPC_GPIO_1_1,
+       .gpio_rst = LPC_GPIO_1_3,
+};
+
+#define ROW(x)   VERTICAL_REV(x)
+DECLARE_FONT(font);
+
+void display_char(uint8_t line, uint8_t col, uint8_t c)
+{
+       uint8_t tile = (c > FIRST_FONT_CHAR) ? (c - FIRST_FONT_CHAR) : 0;
+       uint8_t* tile_data = (uint8_t*)(&font[tile]);
+       ssd130x_buffer_set_tile(gddram, col, line, tile_data);
+}
+int display_line(uint8_t line, uint8_t col, char* text)
+{
+       int len = strlen((char*)text);
+       int i = 0;
+
+       for (i = 0; i < len; i++) {
+               uint8_t tile = (text[i] > FIRST_FONT_CHAR) ? (text[i] - FIRST_FONT_CHAR) : 0;
+               uint8_t* tile_data = (uint8_t*)(&font[tile]);
+               ssd130x_buffer_set_tile(gddram, col++, line, tile_data);
+               if (col >= (SSD130x_NB_COL / 8)) {
+                       col = 0;
+                       line++;
+                       if (line >= SSD130x_NB_PAGES) {
+                               return i;
+                       }
+               }
+       }
+       return len;
+}
+
+/***************************************************************************** */
+/* Communication over USB */
+uint8_t text_received = 0;
+#define NB_CHARS  15
+char inbuff[NB_CHARS + 1];
+void data_rx(uint8_t c)
+{
+       static int idx = 0;
+       if ((c != 0) && (c != '\n') && (c != '\r')) {
+               inbuff[idx++] = c;
+               if (idx >= NB_CHARS) {
+                       inbuff[NB_CHARS] = 0;
+                       idx = 0;
+                       text_received = 1;
+               }
+       } else {
+               if (idx != 0) {
+                       inbuff[idx] = 0;
+                       text_received = 1;
+               }
+               idx = 0;
+       }
+}
+
+
+const struct pio sd_cs = LPC_GPIO_1_0;
+/***************************************************************************** */
+int main(void)
+{
+       int ret = 0;
+       system_init();
+
+       uart_on(UART0, 115200, data_rx);
+       ssp_master_on(SSP_BUS_0, LPC_SSP_FRAME_SPI, 8, 4*1000*1000);
+
+       status_led(green_only);
+
+       config_gpio(&sd_cs, 0, GPIO_DIR_OUT, 1);
+
+       /* Configure and start display */
+       ret = ssd130x_display_on(&display);
+       uprintf(UART0, "display on : %d\n", ret);
+       /* Erase screen with lines, makes it easier to know things are going right */
+       ssd130x_buffer_set(gddram, 0x10);
+       ret = ssd130x_display_full_screen(&display);
+       uprintf(UART0, "full screen : %d\n", ret);
+
+       /* Led strip configuration */
+       ws2812_config(&ws2812_data_out_pin);
+
+       while (1) {
+               chenillard(500);
+               if (text_received != 0) {
+                       display_line(2, 1, inbuff);
+                       ret = ssd130x_display_full_screen(&display);
+                       if (ret != 0) {
+                               uprintf(UART0, "Display update error: %d\n", ret);
+                       } else {
+                               uprintf(UART0, "Display updated.\n");
+                       }
+                       text_received = 0;
+               }
+               ws2812_set_pixel(0, 10, 0, 10);
+               ws2812_set_pixel(1, 15, 5, 5);
+               ws2812_send_frame(0);
+               display_line(1, 0, TEST_VERSION);
+               ret = ssd130x_display_full_screen(&display);
+       }
+       return 0;
+}
+
+
+