[Feature]add MT2731_MP2_MR2_SVN388 baseline version
Change-Id: Ief04314834b31e27effab435d3ca8ba33b499059
diff --git a/src/bsp/lk/target/dartuinoP0/display/LS013B7DH06.c b/src/bsp/lk/target/dartuinoP0/display/LS013B7DH06.c
new file mode 100644
index 0000000..2b1f813
--- /dev/null
+++ b/src/bsp/lk/target/dartuinoP0/display/LS013B7DH06.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2015 Gurjant Kalsi <me@gurjantkalsi.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+// 1.33 Inch 3-Bit RGB Sharp Color LCD
+#include <target/display/LS013B7DH06.h>
+#include <string.h>
+
+#define SET_BIT(BUF, BITNUM) ((BUF)[(BITNUM) >> 3] |= (0xff & (0x1 << ((BITNUM) & 0x07))))
+
+uint8_t lcd_get_line(uint8_t *framebuffer, uint8_t idx, uint8_t *result)
+{
+ framebuffer += MLCD_WIDTH * idx;
+
+ memset(result, 0, MLCD_BYTES_LINE);
+
+ for (int i = 0; i < MLCD_WIDTH; ++i) {
+ uint8_t inpix = framebuffer[i];
+
+ int j = i * 3;
+
+ if (inpix & 0x80) {
+ SET_BIT(result, j);
+ }
+ if (inpix & 0x10) {
+ SET_BIT(result, j + 1);
+ }
+ if (inpix & 0x02) {
+ SET_BIT(result, j + 2);
+ }
+
+ }
+ return MLCD_BYTES_LINE;
+}
\ No newline at end of file
diff --git a/src/bsp/lk/target/dartuinoP0/display/LS027B7DH01.c b/src/bsp/lk/target/dartuinoP0/display/LS027B7DH01.c
new file mode 100644
index 0000000..6e275ca
--- /dev/null
+++ b/src/bsp/lk/target/dartuinoP0/display/LS027B7DH01.c
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2015 Gurjant Kalsi <me@gurjantkalsi.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+// 2.7 Inch Monocromatic Sharp Memory LCD
+
+#include <target/display/LS027B7DH01.h>
+#include <string.h>
+
+#define SET_BIT(BUF, BITNUM) ((BUF)[(BITNUM) >> 3] |= (0xff & (0x1 << ((BITNUM) & 0x07))))
+
+uint8_t lcd_get_line(uint8_t *framebuffer, uint8_t idx, uint8_t *result)
+{
+ framebuffer += MLCD_WIDTH * idx;
+
+ memset(result, 0, MLCD_BYTES_LINE);
+
+ for (uint i = 0; i < MLCD_WIDTH; ++i) {
+ if (framebuffer[i] > 128) {
+ SET_BIT(result, i);
+ }
+ }
+
+ return MLCD_BYTES_LINE;
+}
\ No newline at end of file
diff --git a/src/bsp/lk/target/dartuinoP0/include/target/bmi055.h b/src/bsp/lk/target/dartuinoP0/include/target/bmi055.h
new file mode 100644
index 0000000..7fd75ff
--- /dev/null
+++ b/src/bsp/lk/target/dartuinoP0/include/target/bmi055.h
@@ -0,0 +1,150 @@
+/*
+ * Copyright (c) 2015 Eric Holland
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __SENSOR_BMI055_H
+#define __SENSOR_BMI055_H
+
+#include <sys/types.h>
+
+#define BMI055_ADDRESS_READ(x) (x | 0x80)
+#define BMI055_ADDERSS_WRITE(x) (x & 0x7F)
+
+/**
+* definitions for accelerometer IC
+*/
+#define BMI055_ACC_BGW_CHPID 0x00
+#define BMI055_ACC_ACCD_X_LSB 0X02
+#define BMI055_ACC_ACCD_X_MSB 0X03
+#define BMI055_ACC_ACCD_Y_LSB 0X04
+#define BMI055_ACC_ACCD_Y_MSB 0X05
+#define BMI055_ACC_ACCD_Z_LSB 0X06
+#define BMI055_ACC_ACCD_Z_MSB 0X07
+#define BMI055_ACC_ACCD_TEMP 0X08
+#define BMI055_ACC_INT_STATUS_0 0X09
+#define BMI055_ACC_INT_STATUS_1 0X0a
+#define BMI055_ACC_INT_STATUS_2 0x0b
+#define BMI055_ACC_INT_STATUS_3 0x0c
+#define BMI055_ACC_FIFO_STATUS 0x0e
+#define BMI055_ACC_PMU_RANGE 0x0f
+#define BMI055_ACC_PMU_BW 0x10
+#define BMI055_ACC_PMU_LPW 0x11
+#define BMI055_ACC_PMU_LOW_POWER 0x12
+#define BMI055_ACC_ACCD_HBW 0x13
+#define BMI055_ACC_BGW_SOFTRESET 0x14
+#define BMI055_ACC_INT_EN_0 0x16
+#define BMI055_ACC_INT_EN_1 0x17
+#define BMI055_ACC_INT_EN_2 0x18
+#define BMI055_ACC_INT_MAP_0 0x19
+#define BMI055_ACC_INT_MAP_1 0x1A
+#define BMI055_ACC_INT_MAP_2 0x1B
+#define BMI055_ACC_INT_SRC 0x1E
+#define BMI055_ACC_INT_OUT_CTRL 0x20
+#define BMI055_ACC_INT_RST_LATCH 0x21
+#define BMI055_ACC_INT_0 0x22
+#define BMI055_ACC_INT_1 0x23
+#define BMI055_ACC_INT_2 0x24
+#define BMI055_ACC_INT_3 0x25
+#define BMI055_ACC_INT_4 0x26
+#define BMI055_ACC_INT_5 0x27
+#define BMI055_ACC_INT_6 0x28
+#define BMI055_ACC_INT_7 0x29
+#define BMI055_ACC_INT_8 0x2a
+#define BMI055_ACC_INT_9 0x2b
+#define BMI055_ACC_INT_A 0x2c
+#define BMI055_ACC_INT_B 0x2d
+#define BMI055_ACC_INT_C 0x2e
+#define BMI055_ACC_INT_D 0x2f
+#define BMI055_ACC_FIFO_CONFIG_0 0x30
+#define BMI055_ACC_PMU_SELF_TEST 0x32
+#define BMI055_ACC_TRIM_NVM_CTRL 0x33
+#define BMI055_ACC_BGW_SPI3_WDT 0x34
+#define BMI055_ACC_OFC_CTRL 0x36
+#define BMI055_ACC_OFC_SETTING 0x37
+#define BMI055_ACC_OFC_OFFSET_X 0x38
+#define BMI055_ACC_OFC_OFFSET_Y 0x39
+#define BMI055_ACC_OFC_OFFSET_Z 0x3A
+#define BMI055_ACC_TRIM_GP0 0x3B
+#define BMI055_ACC_TRIM_GP1 0x3C
+#define BMI055_ACC_FIFO_CONFIG_1 0x3E
+#define BMI055_ACC_FIFO_DATA 0x3F
+
+
+/**
+* definitions for gyro IC
+*/
+#define BMI055_GYRO_CHIP_ID 0x00
+#define BMI055_GYRO_RATE_X_LSB 0X02
+#define BMI055_GYRO_RATE_X_MSB 0X03
+#define BMI055_GYRO_RATE_Y_LSB 0X04
+#define BMI055_GYRO_RATE_Y_MSB 0X05
+#define BMI055_GYRO_RATE_Z_LSB 0X06
+#define BMI055_GYRO_RATE_Z_MSB 0X07
+#define BMI055_GYRO_INT_STATUS_0 0X09
+#define BMI055_GYRO_INT_STATUS_1 0X0a
+#define BMI055_GYRO_INT_STATUS_2 0x0b
+#define BMI055_GYRO_INT_STATUS_3 0x0c
+#define BMI055_GYRO_FIFO_STATUS 0x0e
+#define BMI055_GYRO_RANGE 0x0f
+#define BMI055_GYRO_BW 0x10
+#define BMI055_GYRO_LPM1 0x11
+#define BMI055_GYRO_LPM2 0x12
+#define BMI055_GYRO_RATE_HBW 0x13
+#define BMI055_GYRO_BGW_SOFTRESET 0x14
+#define BMI055_GYRO_INT_EN_0 0x15
+#define BMI055_GYRO_INT_EN_1 0x16
+#define BMI055_GYRO_INT_MAP_0 0x17
+#define BMI055_GYRO_INT_MAP_1 0x18
+#define BMI055_GYRO_INT_MAP_2 0x19
+#define BMI055_GYRO_0X1A 0x1A
+#define BMI055_GYRO_0X1B 0x1B
+#define BMI055_GYRO_0X1C 0x1C
+#define BMI055_GYRO_0X1E 0x1E
+#define BMI055_GYRO_INT_RST_LATCH 0x21
+#define BMI055_GYRO_HIGH_TH_X 0x22
+#define BMI055_GYRO_HIGH_DUR_X 0x23
+#define BMI055_GYRO_HIGH_TH_Y 0x24
+#define BMI055_GYRO_HIGH_DUR_Y 0x25
+#define BMI055_GYRO_HIGH_TH_Z 0x26
+#define BMI055_GYRO_HIGH_DUR_Z 0x27
+#define BMI055_GYRO_SOC 0x31
+#define BMI055_GYRO_A_FOC 0x32
+#define BMI055_GYRO_TRIM_NVM_CTRL 0x33
+#define BMI055_GYRO_BGW_SPI3_WDT 0x34
+#define BMI055_GYRO_OFC1 0x36
+#define BMI055_GYRO_OFC2 0x37
+#define BMI055_GYRO_OFC3 0x38
+#define BMI055_GYRO_OFC4 0x39
+#define BMI055_GYRO_TRIM_GP0 0x3A
+#define BMI055_GYRO_TRIM_GP1 0x3B
+#define BMI055_GYRO_BIST 0x3C
+#define BMI055_GYRO_FIFO_CONFIG_0 0x3D
+#define BMI055_GYRO_FIFO_CONFIG_1 0x3E
+
+
+
+
+
+
+
+
+#endif
+
diff --git a/src/bsp/lk/target/dartuinoP0/include/target/debugconfig.h b/src/bsp/lk/target/dartuinoP0/include/target/debugconfig.h
new file mode 100644
index 0000000..02f6ba9
--- /dev/null
+++ b/src/bsp/lk/target/dartuinoP0/include/target/debugconfig.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2012 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __TARGET_DEBUGCONFIG_H
+#define __TARGET_DEBUGCONFIG_H
+
+#define DEBUG_UART 3
+
+#endif
diff --git a/src/bsp/lk/target/dartuinoP0/include/target/display/LS013B7DH06.h b/src/bsp/lk/target/dartuinoP0/include/target/display/LS013B7DH06.h
new file mode 100644
index 0000000..10249b2
--- /dev/null
+++ b/src/bsp/lk/target/dartuinoP0/include/target/display/LS013B7DH06.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2015 Gurjant Kalsi <me@gurjantkalsi.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+// 1.33 Inch 3-Bit RGB Sharp Color LCD
+
+#pragma once
+
+#include <lib/gfx.h>
+
+#define MLCD_WIDTH ((uint16_t)128)
+#define MLCD_HEIGHT ((uint16_t)128)
+#define MLCD_GFX_FORMAT (GFX_FORMAT_RGB_332)
+
+// 3 bits per pixel (1 for each of RBG) divided by 8 bits per byte.
+#define MLCD_BYTES_LINE ((MLCD_WIDTH * 3) / 8)
+
+uint8_t lcd_get_line(uint8_t *framebuffer, uint8_t idx, uint8_t *result);
diff --git a/src/bsp/lk/target/dartuinoP0/include/target/display/LS027B7DH01.h b/src/bsp/lk/target/dartuinoP0/include/target/display/LS027B7DH01.h
new file mode 100644
index 0000000..bde64f6
--- /dev/null
+++ b/src/bsp/lk/target/dartuinoP0/include/target/display/LS027B7DH01.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2015 Gurjant Kalsi <me@gurjantkalsi.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+// 2.7 Inch Monocromatic Sharp Memory LCD
+
+#pragma once
+
+#include <lib/gfx.h>
+
+#define MLCD_WIDTH ((uint16_t)400)
+#define MLCD_HEIGHT ((uint16_t)240)
+#define MLCD_GFX_FORMAT (GFX_FORMAT_MONO)
+
+// 1 bit per pixel divided by 8 bits per byte
+#define MLCD_BYTES_LINE (MLCD_WIDTH / 8)
+
+uint8_t lcd_get_line(uint8_t *framebuffer, uint8_t idx, uint8_t *result);
diff --git a/src/bsp/lk/target/dartuinoP0/include/target/fsconfig.h b/src/bsp/lk/target/dartuinoP0/include/target/fsconfig.h
new file mode 100644
index 0000000..fda5ed6
--- /dev/null
+++ b/src/bsp/lk/target/dartuinoP0/include/target/fsconfig.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2015 Gurjant Kalsi <me@gurjantkalsi.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+ #pragma once
+
+ #define SPIFS_MOUNT_POINT "/spifs"
+ #define SPIFS_NAME "spifs"
+ #define SPIFS_TARGET_DEVICE "qspi-flash"
\ No newline at end of file
diff --git a/src/bsp/lk/target/dartuinoP0/include/target/gpioconfig.h b/src/bsp/lk/target/dartuinoP0/include/target/gpioconfig.h
new file mode 100644
index 0000000..0a1a5cf
--- /dev/null
+++ b/src/bsp/lk/target/dartuinoP0/include/target/gpioconfig.h
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2012 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __TARGET_GPIOCONFIG_H
+#define __TARGET_GPIOCONFIG_H
+
+#include <platform/gpio.h>
+#include <platform/stm32.h>
+
+#define GPIO_LED_ON GPIO_PIN_RESET
+#define GPIO_LED_OFF GPIO_PIN_SET
+
+#define GPIO_USART3_TX GPIO(GPIO_PORT_B, 10)
+#define GPIO_USART3_RX GPIO(GPIO_PORT_B, 11)
+
+#define GPIO_LED108 GPIO(GPIO_PORT_E, 3)
+#define GPIO_LED109 GPIO(GPIO_PORT_E, 4)
+#define GPIO_LED110 GPIO(GPIO_PORT_E, 5)
+#define GPIO_LED111 GPIO(GPIO_PORT_E, 6)
+
+#define GPIO_LED112 GPIO(GPIO_PORT_D, 6)
+#define GPIO_LED113 GPIO(GPIO_PORT_D, 7)
+#define GPIO_LED114 GPIO(GPIO_PORT_J, 10)
+#define GPIO_LED115 GPIO(GPIO_PORT_J, 11)
+
+#define GPIO_SHIELD_D0 GPIO(GPIO_PORT_B, 11)
+#define GPIO_SHIELD_D1 GPIO(GPIO_PORT_B, 10)
+#define GPIO_SHIELD_D2 GPIO(GPIO_PORT_E, 3)
+#define GPIO_SHIELD_D3 GPIO(GPIO_PORT_E, 4)
+#define GPIO_SHIELD_D4 GPIO(GPIO_PORT_E, 5)
+#define GPIO_SHIELD_D5 GPIO(GPIO_PORT_E, 6)
+#define GPIO_SHIELD_D6 GPIO(GPIO_PORT_D, 6)
+#define GPIO_SHIELD_D7 GPIO(GPIO_PORT_D, 7)
+#define GPIO_SHIELD_D8 GPIO(GPIO_PORT_J, 10)
+#define GPIO_SHIELD_D9 GPIO(GPIO_PORT_J, 11)
+#define GPIO_SHIELD_D10 GPIO(GPIO_PORT_J, 12)
+#define GPIO_SHIELD_D11 GPIO(GPIO_PORT_J, 13)
+#define GPIO_SHIELD_D12 GPIO(GPIO_PORT_J, 14)
+#define GPIO_SHIELD_D13 GPIO(GPIO_PORT_J, 15)
+
+#define GPIO_SHIELD_ADC0 GPIO(GPIO_PORT_F, 6)
+#define GPIO_SHIELD_ADC1 GPIO(GPIO_PORT_F, 10)
+#define GPIO_SHIELD_ADC2 GPIO(GPIO_PORT_A, 3)
+#define GPIO_SHIELD_ADC3 GPIO(GPIO_PORT_A, 5)
+#define GPIO_SHIELD_ADC4 GPIO(GPIO_PORT_A, 6)
+#define GPIO_SHIELD_ADC5 GPIO(GPIO_PORT_B, 0)
+
+#define GPIO_SW100 GPIO(GPIO_PORT_J, 12)
+#define GPIO_SW101 GPIO(GPIO_PORT_J, 13)
+#define GPIO_SW102 GPIO(GPIO_PORT_J, 14)
+#define GPIO_SW103 GPIO(GPIO_PORT_J, 15)
+
+/**
+ * Definitions for sensor bus signals. Includes
+ * nrf51, accelerometer, and gyroscope
+ */
+
+#define __HAL_SENSOR_BUS_GPIO_CLK_ENABLE() \
+ __HAL_RCC_GPIOK_CLK_ENABLE(); \
+ __HAL_RCC_GPIOF_CLK_ENABLE()
+
+#define GPIO_NRF_CS GPIO(GPIO_PORT_K, 0)
+#define GPIO_NRF_INT GPIO(GPIO_PORT_K, 1)
+#define GPIO_GYRO_nCS GPIO(GPIO_PORT_K, 4)
+#define GPIO_GYRO_INT GPIO(GPIO_PORT_K, 5)
+#define GPIO_ACC_nCS GPIO(GPIO_PORT_K, 2)
+#define GPIO_ACC_INT GPIO(GPIO_PORT_K, 3)
+#define GPIO_SPI5_SCK GPIO(GPIO_PORT_F, 7)
+#define GPIO_SPI5_MISO GPIO(GPIO_PORT_F, 8)
+#define GPIO_SPI5_MOSI GPIO(GPIO_PORT_F, 9)
+
+
+
+#endif
diff --git a/src/bsp/lk/target/dartuinoP0/include/target/memory_lcd.h b/src/bsp/lk/target/dartuinoP0/include/target/memory_lcd.h
new file mode 100644
index 0000000..410079c
--- /dev/null
+++ b/src/bsp/lk/target/dartuinoP0/include/target/memory_lcd.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2015 Gurjant Kalsi <me@gurjantkalsi.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __TARGET_DARTUINOP0_MEMORY_LCD_H_
+#define __TARGET_DARTUINOP0_MEMORY_LCD_H_
+
+#include <stm32f7xx.h>
+
+// Initialize the QSPI Flash device.
+status_t memory_lcd_init(void);
+
+#endif // __TARGET_DARTUINOP0_MEMORY_LCD_H_
diff --git a/src/bsp/lk/target/dartuinoP0/include/target/sensor_bus.h b/src/bsp/lk/target/dartuinoP0/include/target/sensor_bus.h
new file mode 100644
index 0000000..97b0a4c
--- /dev/null
+++ b/src/bsp/lk/target/dartuinoP0/include/target/sensor_bus.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2015 Eric Holland
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#ifndef __SENSOR_BUS_H
+#define __SENSOR_BUS_H
+
+#include <sys/types.h>
+#include <dev/accelerometer.h>
+
+status_t sensor_bus_init_early(void);
+
+void sensor_bus_init(void);
+
+status_t acc_read(uint8_t address, uint8_t *data);
+
+status_t acc_flush(uint8_t * tbuff, uint8_t * rbuff, uint8_t numbytes);
+
+
+#endif
diff --git a/src/bsp/lk/target/dartuinoP0/init.c b/src/bsp/lk/target/dartuinoP0/init.c
new file mode 100644
index 0000000..0d3d08d
--- /dev/null
+++ b/src/bsp/lk/target/dartuinoP0/init.c
@@ -0,0 +1,486 @@
+/*
+ * Copyright (c) 2015 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#include <err.h>
+#include <stdlib.h>
+#include <debug.h>
+#include <trace.h>
+#include <target.h>
+#include <compiler.h>
+#include <dev/gpio.h>
+#include <dev/usb.h>
+#include <dev/accelerometer.h>
+#include <platform/stm32.h>
+#include <platform/sdram.h>
+#include <platform/gpio.h>
+#include <platform/eth.h>
+#include <platform/qspi.h>
+#include <platform/n25q128a.h>
+#include <target/bmi055.h>
+#include <target/debugconfig.h>
+#include <target/gpioconfig.h>
+#include <target/memory_lcd.h>
+#include <target/sensor_bus.h>
+#include <reg.h>
+
+#if WITH_LIB_MINIP
+#include <lib/minip.h>
+#endif
+
+#if WITH_LIB_FS_SPIFS
+#include <lib/fs.h>
+#include <target/fsconfig.h>
+#endif
+
+extern void target_usb_setup(void);
+
+const sdram_config_t target_sdram_config = {
+ .bus_width = SDRAM_BUS_WIDTH_16,
+ .cas_latency = SDRAM_CAS_LATENCY_2,
+ .col_bits_num = SDRAM_COLUMN_BITS_8
+};
+
+void target_early_init(void)
+{
+ GPIO_InitTypeDef gpio_init;
+
+ __HAL_RCC_GPIOE_CLK_ENABLE();
+ __HAL_RCC_GPIOD_CLK_ENABLE();
+ __HAL_RCC_GPIOJ_CLK_ENABLE();
+
+#if DEBUG_UART == 3
+ // configure usart 3 pins.
+ gpio_config(GPIO_USART3_TX, GPIO_STM32_AF | GPIO_STM32_AFn(GPIO_AF7_USART3) | GPIO_PULLUP);
+ gpio_config(GPIO_USART3_RX, GPIO_STM32_AF | GPIO_STM32_AFn(GPIO_AF7_USART3) | GPIO_PULLUP);
+#else
+#error need to configure gpio pins for debug uart
+#endif
+
+ gpio_init.Mode = GPIO_MODE_OUTPUT_PP;
+ gpio_init.Pull = GPIO_NOPULL;
+ gpio_init.Speed = GPIO_SPEED_LOW;
+
+ gpio_init.Pin = GPIO_TO_PIN_MASK(GPIO_LED108) | GPIO_TO_PIN_MASK(GPIO_LED109) |
+ GPIO_TO_PIN_MASK(GPIO_LED110) | GPIO_TO_PIN_MASK(GPIO_LED111);
+ HAL_GPIO_Init(GPIOE, &gpio_init);
+
+ gpio_init.Pin = GPIO_TO_PIN_MASK(GPIO_LED112) | GPIO_TO_PIN_MASK(GPIO_LED113);
+ HAL_GPIO_Init(GPIOD, &gpio_init);
+
+ gpio_init.Pin = GPIO_TO_PIN_MASK(GPIO_LED114) | GPIO_TO_PIN_MASK(GPIO_LED115);
+ HAL_GPIO_Init(GPIOJ, &gpio_init);
+
+ // Initialize to a pattern just so we know we have something
+ gpio_set(GPIO_LED108, GPIO_LED_ON);
+ gpio_set(GPIO_LED109, GPIO_LED_ON);
+ gpio_set(GPIO_LED110, GPIO_LED_ON);
+ gpio_set(GPIO_LED111, GPIO_LED_ON);
+ gpio_set(GPIO_LED112, GPIO_LED_ON);
+ gpio_set(GPIO_LED113, GPIO_LED_ON);
+ gpio_set(GPIO_LED114, GPIO_LED_ON);
+ gpio_set(GPIO_LED115, GPIO_LED_ON);
+
+ // Initialize the switches GPIOs for interrupt on raising edge. In order
+ // to use stm32_EXTI15_10_IRQ() handler needs to be provided and EXTI15_10_IRQn
+ // needs to be enabled.
+ gpio_init.Mode = GPIO_MODE_INPUT;
+ gpio_init.Pull = GPIO_NOPULL;
+ gpio_init.Speed = GPIO_SPEED_FAST;
+ gpio_init.Mode = GPIO_MODE_IT_RISING;
+
+ gpio_init.Pin = GPIO_TO_PIN_MASK(GPIO_SW100) | GPIO_TO_PIN_MASK(GPIO_SW101) |
+ GPIO_TO_PIN_MASK(GPIO_SW102) | GPIO_TO_PIN_MASK(GPIO_SW103);
+ HAL_GPIO_Init(GPIOJ, &gpio_init);
+
+ // Initialize Sensor bus (accelerometer / gyroscope / nrf51 spi bus
+ sensor_bus_init_early();
+
+ // now that the uart gpios are configured, enable the debug uart.
+ stm32_debug_early_init();
+
+ // default all the debug leds to off
+ target_set_debug_led(0, false);
+ target_set_debug_led(1, false);
+ target_set_debug_led(2, false);
+ target_set_debug_led(3, false);
+}
+
+
+void target_init(void)
+{
+ stm32_debug_init();
+
+ qspi_flash_init(N25Q128A_FLASH_SIZE);
+
+ memory_lcd_init();
+
+#if WITH_LIB_MINIP
+ uint8_t mac_addr[6];
+ gen_random_mac_address(mac_addr);
+ eth_init(mac_addr, PHY_KSZ8721);
+
+ /* start minip */
+ minip_set_macaddr(mac_addr);
+
+ uint32_t ip_addr = IPV4(192, 168, 0, 98);
+ uint32_t ip_mask = IPV4(255, 255, 255, 0);
+ uint32_t ip_gateway = IPV4_NONE;
+
+ minip_init(stm32_eth_send_minip_pkt, NULL, ip_addr, ip_mask, ip_gateway);
+#endif
+
+#if WITH_LIB_FS_SPIFS
+ status_t mount_success =
+ fs_mount(SPIFS_MOUNT_POINT, SPIFS_NAME, SPIFS_TARGET_DEVICE);
+ if (mount_success != NO_ERROR) {
+ printf("failed to mount '%s' at path '%s' on '%s'."
+ " Make sure that device is formatted\n",
+ SPIFS_NAME, SPIFS_MOUNT_POINT, SPIFS_TARGET_DEVICE);
+ }
+
+#endif
+
+ // start usb
+ target_usb_setup();
+
+ sensor_bus_init();
+}
+
+void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi)
+{
+ GPIO_InitTypeDef GPIO_InitStruct;
+ if (hspi->Instance == SPI2) {
+ /*##-1- Enable peripherals and GPIO Clocks #################################*/
+ /* Enable GPIO TX/RX clock */
+ __HAL_RCC_GPIOD_CLK_ENABLE();
+ __HAL_RCC_GPIOK_CLK_ENABLE();
+ __HAL_RCC_GPIOB_CLK_ENABLE();
+ /* Enable SPI clock */
+ __HAL_RCC_SPI2_CLK_ENABLE();
+
+ /*##-2- Configure peripheral GPIO ##########################################*/
+ /* SPI SCK GPIO pin configuration */
+ GPIO_InitStruct.Pin = GPIO_PIN_3;
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+ GPIO_InitStruct.Pull = GPIO_PULLDOWN;
+ GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
+ GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
+ HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
+
+ /* SPI MOSI GPIO pin configuration */
+ GPIO_InitStruct.Pin = GPIO_PIN_15;
+ HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
+
+ GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+
+ /* LCD_ON Pin configuration */
+ GPIO_InitStruct.Pin = GPIO_PIN_6;
+ HAL_GPIO_Init(GPIOK, &GPIO_InitStruct);
+
+ /* LCD_CS Pin configuration */
+ GPIO_InitStruct.Pin = GPIO_PIN_12;
+ HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
+
+
+ /*##-3- Configure the NVIC for SPI #########################################*/
+ /* NVIC for SPI */
+ HAL_NVIC_EnableIRQ(SPI2_IRQn);
+ }
+}
+
+/**
+ * @brief Initializes SDRAM GPIO.
+ * called back from stm32_sdram_init
+ */
+void stm_sdram_GPIO_init(void)
+{
+ GPIO_InitTypeDef gpio_init_structure;
+
+ /* Enable GPIOs clock */
+ __HAL_RCC_GPIOC_CLK_ENABLE();
+ __HAL_RCC_GPIOD_CLK_ENABLE();
+ __HAL_RCC_GPIOE_CLK_ENABLE();
+ __HAL_RCC_GPIOF_CLK_ENABLE();
+ __HAL_RCC_GPIOG_CLK_ENABLE();
+ __HAL_RCC_GPIOH_CLK_ENABLE();
+
+ /* Common GPIO configuration */
+ gpio_init_structure.Mode = GPIO_MODE_AF_PP;
+ gpio_init_structure.Pull = GPIO_PULLUP;
+ gpio_init_structure.Speed = GPIO_SPEED_FAST;
+ gpio_init_structure.Alternate = GPIO_AF12_FMC;
+
+ /* GPIOC configuration */
+ gpio_init_structure.Pin = GPIO_PIN_3;
+ HAL_GPIO_Init(GPIOC, &gpio_init_structure);
+
+ /* GPIOD configuration */
+ gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_3 | GPIO_PIN_8| GPIO_PIN_9 | GPIO_PIN_10 |\
+ GPIO_PIN_14 | GPIO_PIN_15;
+ HAL_GPIO_Init(GPIOD, &gpio_init_structure);
+
+ /* GPIOE configuration */
+ gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_7| GPIO_PIN_8 | GPIO_PIN_9 |\
+ GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 |\
+ GPIO_PIN_15;
+ HAL_GPIO_Init(GPIOE, &gpio_init_structure);
+
+ /* GPIOF configuration */
+ gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2| GPIO_PIN_3 | GPIO_PIN_4 |\
+ GPIO_PIN_5 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 |\
+ GPIO_PIN_15;
+ HAL_GPIO_Init(GPIOF, &gpio_init_structure);
+
+ /* GPIOG configuration */
+ gpio_init_structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_4| GPIO_PIN_5 | GPIO_PIN_8 |\
+ GPIO_PIN_15;
+ HAL_GPIO_Init(GPIOG, &gpio_init_structure);
+
+ /* GPIOH configuration */
+ gpio_init_structure.Pin = GPIO_PIN_3 | GPIO_PIN_5;
+ HAL_GPIO_Init(GPIOH, &gpio_init_structure);
+}
+
+
+/**
+ * @brief Initializes the ETH MSP.
+ * @param heth: ETH handle
+ * @retval None
+ */
+/* called back from the HAL_ETH_Init routine */
+void HAL_ETH_MspInit(ETH_HandleTypeDef *heth)
+{
+ GPIO_InitTypeDef GPIO_InitStructure;
+
+ /* Enable GPIOs clocks */
+ __HAL_RCC_GPIOA_CLK_ENABLE();
+ __HAL_RCC_GPIOC_CLK_ENABLE();
+ __HAL_RCC_GPIOG_CLK_ENABLE();
+
+ /* Ethernet pins configuration ************************************************/
+ /*
+ RMII_REF_CLK ----------------------> PA1
+ RMII_MDIO -------------------------> PA2
+ RMII_MDC --------------------------> PC1
+ RMII_MII_CRS_DV -------------------> PA7
+ RMII_MII_RXD0 ---------------------> PC4
+ RMII_MII_RXD1 ---------------------> PC5
+ RMII_MII_TX_EN --------------------> PG11
+ RMII_MII_TXD0 ---------------------> PG13
+ RMII_MII_TXD1 ---------------------> PG14
+ */
+
+ /* Configure PA1, PA2 and PA7 */
+ GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
+ GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
+ GPIO_InitStructure.Pull = GPIO_NOPULL;
+ GPIO_InitStructure.Alternate = GPIO_AF11_ETH;
+ GPIO_InitStructure.Pin = GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_7;
+ HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
+
+ /* Configure PC1, PC4 and PC5 */
+ GPIO_InitStructure.Pin = GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5;
+ HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
+
+ /* Configure PG2, PG11, PG13 and PG14 */
+ GPIO_InitStructure.Pin = GPIO_PIN_2 | GPIO_PIN_11 | GPIO_PIN_13 | GPIO_PIN_14;
+ HAL_GPIO_Init(GPIOG, &GPIO_InitStructure);
+}
+
+void HAL_QSPI_MspInit(QSPI_HandleTypeDef *hqspi)
+{
+ GPIO_InitTypeDef GPIO_InitStruct;
+
+ /*##-1- Enable peripherals and GPIO Clocks #################################*/
+ /* Enable GPIO clocks */
+ __HAL_RCC_GPIOB_CLK_ENABLE();
+ __HAL_RCC_GPIOD_CLK_ENABLE();
+ __HAL_RCC_GPIOE_CLK_ENABLE();
+
+ /*##-2- Configure peripheral GPIO ##########################################*/
+ /* QSPI CS GPIO pin configuration */
+ GPIO_InitStruct.Pin = GPIO_PIN_6;
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+ GPIO_InitStruct.Pull = GPIO_PULLUP;
+ GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
+ GPIO_InitStruct.Alternate = GPIO_AF10_QUADSPI;
+ HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
+
+ /* QSPI CLK GPIO pin configuration */
+ GPIO_InitStruct.Pin = GPIO_PIN_2;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
+ HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
+
+ /* QSPI D0 GPIO pin configuration */
+ GPIO_InitStruct.Pin = GPIO_PIN_11;
+ GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
+ HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
+
+ /* QSPI D1 GPIO pin configuration */
+ GPIO_InitStruct.Pin = GPIO_PIN_12;
+ GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
+ HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
+
+ /* QSPI D2 GPIO pin configuration */
+ GPIO_InitStruct.Pin = GPIO_PIN_2;
+ GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
+ HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
+
+ /* QSPI D3 GPIO pin configuration */
+ GPIO_InitStruct.Pin = GPIO_PIN_13;
+ GPIO_InitStruct.Alternate = GPIO_AF9_QUADSPI;
+ HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
+}
+
+/**
+ * @brief Initializes the PCD MSP.
+ * @param hpcd: PCD handle
+ * @retval None
+ */
+void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd)
+{
+ GPIO_InitTypeDef GPIO_InitStruct;
+
+ if (hpcd->Instance == USB_OTG_FS) {
+ /* Configure USB FS GPIOs */
+ __HAL_RCC_GPIOA_CLK_ENABLE();
+
+ /* Configure DM DP Pins */
+ GPIO_InitStruct.Pin = (GPIO_PIN_11 | GPIO_PIN_12);
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
+ GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
+ HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+
+ /* Enable USB FS Clock */
+ __HAL_RCC_USB_OTG_FS_CLK_ENABLE();
+
+ /* Set USBFS Interrupt priority */
+ HAL_NVIC_SetPriority(OTG_FS_IRQn, 5, 0);
+
+ /* Enable USBFS Interrupt */
+ HAL_NVIC_EnableIRQ(OTG_FS_IRQn);
+
+ if (hpcd->Init.low_power_enable == 1) {
+ /* Enable EXTI Line 18 for USB wakeup*/
+ __HAL_USB_OTG_FS_WAKEUP_EXTI_CLEAR_FLAG();
+ __HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_RISING_EDGE();
+ __HAL_USB_OTG_FS_WAKEUP_EXTI_ENABLE_IT();
+
+ /* Set EXTI Wakeup Interrupt priority*/
+ HAL_NVIC_SetPriority(OTG_FS_WKUP_IRQn, 0, 0);
+
+ /* Enable EXTI Interrupt */
+ HAL_NVIC_EnableIRQ(OTG_FS_WKUP_IRQn);
+ }
+ } else if (hpcd->Instance == USB_OTG_HS) {
+ /* Configure USB FS GPIOs */
+ __HAL_RCC_GPIOA_CLK_ENABLE();
+ __HAL_RCC_GPIOB_CLK_ENABLE();
+ __HAL_RCC_GPIOC_CLK_ENABLE();
+ __HAL_RCC_GPIOH_CLK_ENABLE();
+
+ /* CLK */
+ GPIO_InitStruct.Pin = GPIO_PIN_5;
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
+ GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
+ HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+
+ /* D0 */
+ GPIO_InitStruct.Pin = GPIO_PIN_3;
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
+ GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
+ HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+
+ /* D1 D2 D3 D4 D5 D6 D7 */
+ GPIO_InitStruct.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_5 |\
+ GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13;
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
+ HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
+
+ /* STP */
+ GPIO_InitStruct.Pin = GPIO_PIN_0;
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
+ HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
+
+ /* NXT */
+ GPIO_InitStruct.Pin = GPIO_PIN_4;
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
+ HAL_GPIO_Init(GPIOH, &GPIO_InitStruct);
+
+ /* DIR */
+ GPIO_InitStruct.Pin = GPIO_PIN_2;
+ GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
+ GPIO_InitStruct.Pull = GPIO_NOPULL;
+ GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
+ HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
+
+ __HAL_RCC_USB_OTG_HS_ULPI_CLK_ENABLE();
+
+ /* Enable USB HS Clocks */
+ __HAL_RCC_USB_OTG_HS_CLK_ENABLE();
+
+ /* Set USBHS Interrupt to the lowest priority */
+ HAL_NVIC_SetPriority(OTG_HS_IRQn, 5, 0);
+
+ /* Enable USBHS Interrupt */
+ HAL_NVIC_EnableIRQ(OTG_HS_IRQn);
+ }
+}
+
+void target_set_debug_led(unsigned int led, bool on)
+{
+ uint32_t gpio;
+
+ switch (led) {
+ case 0:
+ gpio = GPIO_LED112;
+ break;
+ case 1:
+ gpio = GPIO_LED113;
+ break;
+ case 2:
+ gpio = GPIO_LED114;
+ break;
+ case 3:
+ gpio = GPIO_LED115;
+ break;
+ default:
+ return;
+ }
+
+ gpio_set(gpio, on ? GPIO_LED_ON : GPIO_LED_OFF);
+}
+
diff --git a/src/bsp/lk/target/dartuinoP0/memory_lcd.c b/src/bsp/lk/target/dartuinoP0/memory_lcd.c
new file mode 100644
index 0000000..c73f85d
--- /dev/null
+++ b/src/bsp/lk/target/dartuinoP0/memory_lcd.c
@@ -0,0 +1,167 @@
+/*
+ * Copyright (c) 2015 Gurjant Kalsi <me@gurjantkalsi.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <err.h>
+#include <debug.h>
+#include <trace.h>
+#include <rand.h>
+
+#include <dev/display.h>
+#include <lib/gfx.h>
+#include <platform/gpio.h>
+#include <target/memory_lcd.h>
+
+#if defined (LCD_LS013B7DH06)
+#include <target/display/LS013B7DH06.h>
+#elif defined (LCD_LS027B7DH01)
+#include <target/display/LS027B7DH01.h>
+#endif
+
+#define LOCAL_TRACE 0
+
+SPI_HandleTypeDef SpiHandle;
+
+#define MLCD_WR 0x01 // LCD Write Command
+#define MLCD_CM 0x04 // LCD Clear Memory Command
+#define MLCD_NO 0x00 // LCD No-op command
+
+// 5 bytes used as control bytes, MLCD_BYTES_LINE bytes used to data
+#define MLCD_BUF_SIZE (MLCD_BYTES_LINE + 5)
+
+#define VCOM_HI 0x02
+#define VCOM_LO 0x00
+
+static uint8_t framebuffer[MLCD_HEIGHT * MLCD_WIDTH];
+static uint8_t vcom_state;
+
+static void chip_select(bool s)
+{
+ if (s) {
+ gpio_set(GPIO(GPIO_PORT_B, 12), GPIO_PIN_SET);
+ } else {
+ gpio_set(GPIO(GPIO_PORT_B, 12), GPIO_PIN_RESET);
+ }
+}
+
+static void lcd_power(bool s)
+{
+ if (s) {
+ gpio_set(GPIO(GPIO_PORT_K, 6), GPIO_PIN_SET);
+ } else {
+ gpio_set(GPIO(GPIO_PORT_K, 6), GPIO_PIN_RESET);
+ }
+}
+
+static void mlcd_clear(void)
+{
+
+ uint8_t clear[2];
+ clear[0] = MLCD_CM;
+ clear[1] = 0;
+
+ chip_select(true);
+ HAL_SPI_Transmit(&SpiHandle, clear, 2, HAL_MAX_DELAY);
+ chip_select(false);
+}
+
+
+status_t memory_lcd_init(void)
+{
+ SpiHandle.Instance = SPI2;
+ SpiHandle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;
+ SpiHandle.Init.Direction = SPI_DIRECTION_1LINE;
+ SpiHandle.Init.CLKPhase = SPI_PHASE_1EDGE;
+ SpiHandle.Init.CLKPolarity = SPI_POLARITY_LOW;
+ SpiHandle.Init.DataSize = SPI_DATASIZE_8BIT;
+ SpiHandle.Init.FirstBit = SPI_FIRSTBIT_LSB;
+ SpiHandle.Init.TIMode = SPI_TIMODE_DISABLE;
+ SpiHandle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
+ SpiHandle.Init.CRCPolynomial = 7;
+ SpiHandle.Init.NSS = SPI_NSS_SOFT;
+ SpiHandle.Init.Mode = SPI_MODE_MASTER;
+
+ if (HAL_SPI_Init(&SpiHandle) != HAL_OK) {
+ return ERR_GENERIC;
+ }
+
+ vcom_state = VCOM_LO;
+
+ lcd_power(true);
+
+ mlcd_clear();
+
+ return NO_ERROR;
+}
+
+
+
+static void mlcd_flush(uint starty, uint endy)
+{
+ chip_select(true);
+
+ static uint8_t localbuf[MLCD_BUF_SIZE];
+ uint8_t *bufptr = localbuf;
+
+ // The first line is preceeded with a write command.
+ *bufptr++ = MLCD_WR | vcom_state;
+
+ vcom_state = vcom_state == VCOM_HI ? VCOM_LO : VCOM_HI;
+
+ // Send the image data.
+ for (uint j = starty; j <= endy; ++j) {
+ *bufptr++ = (j + 1);
+
+ bufptr += lcd_get_line(framebuffer, j, bufptr);
+
+ if (HAL_SPI_Transmit(&SpiHandle, localbuf, bufptr - localbuf, HAL_MAX_DELAY) != HAL_OK) {
+ goto finish;
+ }
+
+ bufptr = localbuf;
+
+ *bufptr++ = (j + 1);
+ }
+
+ uint8_t trailer = 0;
+ if (HAL_SPI_Transmit(&SpiHandle, &trailer, 1, HAL_MAX_DELAY) != HAL_OK) {
+ goto finish;
+ }
+
+
+finish:
+ chip_select(false);
+}
+
+status_t display_get_info(struct display_info *info)
+{
+ LTRACEF("display_info %p\n", info);
+
+ info->framebuffer = (void*)framebuffer;
+ info->format = MLCD_GFX_FORMAT;
+ info->width = MLCD_WIDTH;
+ info->height = MLCD_HEIGHT;
+ info->stride = MLCD_WIDTH;
+ info->flush = mlcd_flush;
+
+ return NO_ERROR;
+}
diff --git a/src/bsp/lk/target/dartuinoP0/rules.mk b/src/bsp/lk/target/dartuinoP0/rules.mk
new file mode 100644
index 0000000..5271f9e
--- /dev/null
+++ b/src/bsp/lk/target/dartuinoP0/rules.mk
@@ -0,0 +1,61 @@
+LOCAL_DIR := $(GET_LOCAL_DIR)
+
+MODULE := $(LOCAL_DIR)
+
+STM32_CHIP := stm32f756
+
+PLATFORM := stm32f7xx
+
+SDRAM_SIZE := 0x00800000
+SDRAM_BASE := 0xc0000000
+
+DISPLAY_PANEL_TYPE ?= LS013B7DH06
+
+GLOBAL_DEFINES += \
+ ENABLE_UART3=1 \
+ ENABLE_SDRAM=1 \
+ USE_HSE_XTAL=1 \
+ SDRAM_BASE=$(SDRAM_BASE) \
+ SDRAM_SIZE=$(SDRAM_SIZE) \
+ PLL_M_VALUE=8 \
+ PLL_N_VALUE=336 \
+ PLL_P_VALUE=2 \
+\
+ PKTBUF_POOL_SIZE=16 \
+\
+ TARGET_HAS_DEBUG_LED=1
+
+MODULE_DEPS += \
+ app/accelerometer \
+
+GLOBAL_INCLUDES += $(LOCAL_DIR)/include
+
+MODULE_SRCS += \
+ $(LOCAL_DIR)/init.c \
+ $(LOCAL_DIR)/sensor_bus.c \
+ $(LOCAL_DIR)/usb.c \
+
+ifneq ($(DISPLAY_PANEL_TYPE),)
+MODULE_DEPS += \
+ lib/gfx
+
+MODULE_SRCS += \
+ $(LOCAL_DIR)/memory_lcd.c
+endif
+
+ifeq ($(DISPLAY_PANEL_TYPE),LS013B7DH06)
+GLOBAL_DEFINES += \
+ LCD_LS013B7DH06=1
+
+MODULE_SRCS += \
+ $(LOCAL_DIR)/display/LS013B7DH06.c
+else ifeq ($(DISPLAY_PANEL_TYPE),LS027B7DH01)
+GLOBAL_DEFINES += \
+ LCD_LS027B7DH01=1
+
+MODULE_SRCS += \
+ $(LOCAL_DIR)/display/LS027B7DH01.c
+endif
+
+include make/module.mk
+
diff --git a/src/bsp/lk/target/dartuinoP0/sensor_bus.c b/src/bsp/lk/target/dartuinoP0/sensor_bus.c
new file mode 100644
index 0000000..82f608a
--- /dev/null
+++ b/src/bsp/lk/target/dartuinoP0/sensor_bus.c
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2015 Eric Holland
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#include <err.h>
+#include <kernel/mutex.h>
+#include <platform/gpio.h>
+#include <target/gpioconfig.h>
+#include <target/bmi055.h>
+#include <target/sensor_bus.h>
+#include <dev/accelerometer.h>
+
+static mutex_t sensorbus_mutex;
+static SPI_HandleTypeDef spi_handle;
+
+static uint8_t tx_buff[16];
+static uint8_t rx_buff[16];
+
+status_t acc_read_xyz(position_vector_t * pos_vector_p)
+{
+ tx_buff[0] = BMI055_ADDRESS_READ( BMI055_ACC_ACCD_X_LSB );
+ if ( acc_flush(tx_buff, rx_buff, 7) == NO_ERROR )
+ {
+ pos_vector_p->x = 0.001*(((int8_t)rx_buff[2] << 4) | ( (rx_buff[1] >> 4) & 0x0F));
+ pos_vector_p->y = 0.001*(((int8_t)rx_buff[4] << 4) | ( (rx_buff[3] >> 4) & 0x0F));
+ pos_vector_p->z = 0.001*(((int8_t)rx_buff[6] << 4) | ( (rx_buff[5] >> 4) & 0x0F));
+ return NO_ERROR;
+ }
+ else {
+ return ERR_GENERIC;
+ }
+}
+
+status_t acc_flush(uint8_t * tbuff, uint8_t * rbuff, uint8_t numbytes)
+{
+ status_t ret_status;
+
+ mutex_acquire(&sensorbus_mutex);
+
+ gpio_set(GPIO_ACC_nCS,GPIO_PIN_RESET);
+
+ ret_status = HAL_SPI_TransmitReceive(&spi_handle, tbuff, rbuff, numbytes, 5000);
+
+ gpio_set(GPIO_ACC_nCS,GPIO_PIN_SET);
+
+ mutex_release(&sensorbus_mutex);
+
+ return ret_status;
+}
+
+/**
+ * @brief Initiale SPI5 module and IO for control of spi bus linking nrf51, accelerometer, and gyroscope.
+ *
+ */
+status_t sensor_bus_init_early(void)
+{
+ __HAL_SENSOR_BUS_GPIO_CLK_ENABLE();
+ __HAL_RCC_SPI5_CLK_ENABLE();
+
+ gpio_config(GPIO_SPI5_SCK, GPIO_STM32_AF | GPIO_STM32_AFn(GPIO_AF5_SPI5) | GPIO_PULLUP);
+ gpio_config(GPIO_SPI5_MISO, GPIO_STM32_AF | GPIO_STM32_AFn(GPIO_AF5_SPI5) | GPIO_PULLUP);
+ gpio_config(GPIO_SPI5_MOSI, GPIO_STM32_AF | GPIO_STM32_AFn(GPIO_AF5_SPI5) | GPIO_PULLUP);
+
+ gpio_config(GPIO_NRF_CS, GPIO_OUTPUT );
+ gpio_config(GPIO_NRF_INT, GPIO_INPUT | GPIO_PULLUP);
+
+ gpio_config(GPIO_GYRO_nCS, GPIO_OUTPUT );
+ gpio_config(GPIO_GYRO_INT, GPIO_INPUT | GPIO_PULLUP);
+
+ gpio_config(GPIO_ACC_nCS, GPIO_OUTPUT );
+ gpio_config(GPIO_ACC_INT, GPIO_INPUT | GPIO_PULLUP);
+
+ gpio_set(GPIO_NRF_CS, GPIO_PIN_RESET);
+ gpio_set(GPIO_GYRO_nCS, GPIO_PIN_SET);
+ gpio_set(GPIO_ACC_nCS, GPIO_PIN_SET);
+
+ spi_handle.Instance = SPI5;
+ spi_handle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128;
+ spi_handle.Init.Direction = SPI_DIRECTION_2LINES;
+ spi_handle.Init.CLKPhase = SPI_PHASE_1EDGE;
+ spi_handle.Init.CLKPolarity = SPI_POLARITY_LOW;
+ spi_handle.Init.DataSize = SPI_DATASIZE_8BIT;
+ spi_handle.Init.FirstBit = SPI_FIRSTBIT_MSB;
+ spi_handle.Init.TIMode = SPI_TIMODE_DISABLE;
+ spi_handle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
+ spi_handle.Init.CRCPolynomial = 7;
+ spi_handle.Init.NSS = SPI_NSS_SOFT;
+ spi_handle.Init.Mode = SPI_MODE_MASTER;
+
+ if (HAL_SPI_Init(&spi_handle) != HAL_OK) {
+ return ERR_GENERIC;
+ }
+ return NO_ERROR;
+}
+
+
+
+void sensor_bus_init(void)
+{
+ mutex_init(&sensorbus_mutex);
+}
+
+
diff --git a/src/bsp/lk/target/dartuinoP0/usb.c b/src/bsp/lk/target/dartuinoP0/usb.c
new file mode 100644
index 0000000..2689b44
--- /dev/null
+++ b/src/bsp/lk/target/dartuinoP0/usb.c
@@ -0,0 +1,219 @@
+/*
+ * Copyright (c) 2013-2015 Travis Geiselbrecht
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files
+ * (the "Software"), to deal in the Software without restriction,
+ * including without limitation the rights to use, copy, modify, merge,
+ * publish, distribute, sublicense, and/or sell copies of the Software,
+ * and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#include <err.h>
+#include <debug.h>
+#include <stdio.h>
+#include <trace.h>
+#include <target.h>
+#include <compiler.h>
+#include <dev/usb.h>
+#include <dev/usbc.h>
+#include <hw/usb.h>
+#include <lk/init.h>
+
+#define LOCAL_TRACE 0
+
+#define W(w) (w & 0xff), (w >> 8)
+#define W3(w) (w & 0xff), ((w >> 8) & 0xff), ((w >> 16) & 0xff)
+
+/* top level device descriptor */
+static const uint8_t dev_descr[] = {
+ 0x12, /* descriptor length */
+ DEVICE, /* Device Descriptor type */
+ W(0x0200), /* USB Version */
+ 0xff, /* class */
+ 0xff, /* subclass */
+ 0xff, /* protocol */
+ 64, /* max packet size, ept0 */
+ W(0x9999), /* vendor */
+ W(0x9999), /* product */
+ W(0x9999), /* release */
+ 0x2, /* manufacturer string */
+ 0x1, /* product string */
+ 0x0, /* serialno string */
+ 0x1, /* num configs */
+};
+
+/* high/low speed device qualifier */
+static const uint8_t devqual_descr[] = {
+ 0x0a, /* len */
+ DEVICE_QUALIFIER, /* Device Qualifier type */
+ W(0x0200), /* USB version */
+ 0x00, /* class */
+ 0x00, /* subclass */
+ 0x00, /* protocol */
+ 64, /* max packet size, ept0 */
+ 0x01, /* num configs */
+ 0x00 /* reserved */
+};
+
+static const uint8_t cfg_descr[] = {
+ 0x09, /* Length of Cfg Descr */
+ CONFIGURATION, /* Type of Cfg Descr */
+ W(0x09), /* Total Length (incl ifc, ept) */
+ 0x00, /* # Interfaces */
+ 0x01, /* Cfg Value */
+ 0x00, /* Cfg String */
+ 0xc0, /* Attributes -- self powered */
+ 250, /* Power Consumption - 500mA */
+};
+
+static const uchar langid[] = { 0x04, 0x03, 0x09, 0x04 };
+
+static const uint8_t if_descriptor_lowspeed[] = {
+ 0x09, /* length */
+ INTERFACE, /* type */
+ 0x01, /* interface num */
+ 0x00, /* alternates */
+ 0x02, /* endpoint count */
+ 0xff, /* interface class */
+ 0xff, /* interface subclass */
+ 0x00, /* interface protocol */
+ 0x00, /* string index */
+
+ /* endpoint 1 IN */
+ 0x07, /* length */
+ ENDPOINT, /* type */
+ 0x81, /* address: 1 IN */
+ 0x02, /* type: bulk */
+ W(64), /* max packet size: 64 */
+ 00, /* interval */
+
+ /* endpoint 1 OUT */
+ 0x07, /* length */
+ ENDPOINT, /* type */
+ 0x01, /* address: 1 OUT */
+ 0x02, /* type: bulk */
+ W(64), /* max packet size: 64 */
+ 00, /* interval */
+};
+
+usb_config config = {
+ .lowspeed = {
+ .device = USB_DESC_STATIC(dev_descr),
+ .device_qual = USB_DESC_STATIC(devqual_descr),
+ .config = USB_DESC_STATIC(cfg_descr),
+ },
+ .highspeed = {
+ .device = USB_DESC_STATIC(dev_descr),
+ .device_qual = USB_DESC_STATIC(devqual_descr),
+ .config = USB_DESC_STATIC(cfg_descr),
+ },
+
+ .langid = USB_DESC_STATIC(langid),
+};
+
+static status_t ep_cb_rx(ep_t endpoint, usbc_transfer_t *t);
+static status_t ep_cb_tx(ep_t endpoint, usbc_transfer_t *t);
+
+static void queue_rx(void)
+{
+ static usbc_transfer_t transfer;
+ static uint8_t buf[512];
+
+ transfer.callback = &ep_cb_rx;
+ transfer.result = 0;
+ transfer.buf = &buf;
+ transfer.buflen = sizeof(buf);
+ transfer.bufpos = 0;
+ transfer.extra = 0;
+
+ usbc_queue_rx(1, &transfer);
+}
+
+static void queue_tx(void)
+{
+ static usbc_transfer_t transfer;
+ static uint8_t buf[512];
+
+ for (uint i = 0; i < sizeof(buf); i++) {
+ buf[i] = ~i;
+ }
+
+ transfer.callback = &ep_cb_tx;
+ transfer.result = 0;
+ transfer.buf = &buf;
+ transfer.buflen = sizeof(buf);
+ transfer.bufpos = 0;
+ transfer.extra = 0;
+
+ usbc_queue_tx(1, &transfer);
+}
+
+static status_t ep_cb_rx(ep_t endpoint, usbc_transfer_t *t)
+{
+#if LOCAL_TRACE
+ LTRACEF("ep %u transfer %p\n", endpoint, t);
+ usbc_dump_transfer(t);
+
+ if (t->result >= 0) {
+ hexdump8(t->buf, t->bufpos);
+ }
+#endif
+
+ if (t->result >= 0)
+ queue_rx();
+
+ return NO_ERROR;
+}
+
+static status_t ep_cb_tx(ep_t endpoint, usbc_transfer_t *t)
+{
+#if LOCAL_TRACE
+ LTRACEF("ep %u transfer %p\n", endpoint, t);
+ usbc_dump_transfer(t);
+#endif
+
+ if (t->result >= 0)
+ queue_tx();
+
+ return NO_ERROR;
+}
+
+static status_t usb_cb(void *cookie, usb_callback_op_t op, const union usb_callback_args *args)
+{
+ LTRACEF("cookie %p, op %u, args %p\n", cookie, op, args);
+
+ if (op == USB_CB_ONLINE) {
+ usbc_setup_endpoint(1, USB_IN, 0x40);
+ usbc_setup_endpoint(1, USB_OUT, 0x40);
+
+ queue_rx();
+ queue_tx();
+ }
+ return NO_ERROR;
+}
+
+void target_usb_setup(void)
+{
+ usb_setup(&config);
+ printf("appending interfaces\n");
+ usb_append_interface_lowspeed(if_descriptor_lowspeed, sizeof(if_descriptor_lowspeed));
+ usb_append_interface_highspeed(if_descriptor_lowspeed, sizeof(if_descriptor_lowspeed));
+
+ usb_add_string("LK", 1);
+ usb_add_string("LK Industries", 2);
+
+ usb_register_callback(&usb_cb, NULL);
+ usb_start();
+}