boards: pinetime_devkit0 basic sample.

Basic sample program that uses the one led and button from the Pinetime.
Led will turn on everytime the button is pushed.

Signed-off-by: Rafa Couto <caligari@treboada.net>
This commit is contained in:
Rafa Couto 2019-11-21 01:45:13 +01:00 committed by Carles Cufí
parent 0dbc7e20be
commit ce9947c243
4 changed files with 43 additions and 2 deletions

View file

@ -101,9 +101,9 @@
};
/* Hynitron CST816S Capacitive Touch Controller (400KHz) */
cst816s: cst816s@37 {
cst816s: cst816s@15 {
compatible = "hynitron,cst816s";
reg = <0x37>; /* datasheet pending! */
reg = <0x15>;
label = "CST816S";
irq-gpios = <&gpio0 28 GPIO_INT_ACTIVE_LOW>;
rst-gpios = <&gpio0 10 GPIO_INT_ACTIVE_LOW>;

View file

@ -0,0 +1,9 @@
# Boilerplate code, which pulls in the Zephyr build system.
cmake_minimum_required(VERSION 3.13.1)
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
project(sample_pinetime_app)
# Add your source file to the "app" target. This must come after
# the boilerplate code, which defines the target.
target_sources(app PRIVATE src/main.c)

View file

View file

@ -0,0 +1,32 @@
#include <zephyr.h>
#include <drivers/gpio.h>
#define LED_PORT DT_ALIAS_STATUS_LED_GPIOS_CONTROLLER
#define LED_PIN DT_ALIAS_STATUS_LED_GPIOS_PIN
#define BTN_PORT DT_ALIAS_KEY_IN_GPIOS_CONTROLLER
#define BTN_PIN DT_ALIAS_KEY_IN_GPIOS_PIN
int main(void)
{
struct device *dev_led = device_get_binding(LED_PORT);
gpio_pin_configure(dev_led, LED_PIN, GPIO_DIR_OUT);
struct device *dev_btn = device_get_binding(BTN_PORT);
gpio_pin_configure(dev_btn, BTN_PIN, GPIO_DIR_IN);
while (1)
{
// button is pressed ==> turn on status LED
u32_t val = 0U;
gpio_pin_read(dev_btn, BTN_PIN, &val);
gpio_pin_write(dev_led, LED_PIN, val);
// dont burn the CPU
k_sleep(10);
}
return 0;
}