--- /dev/null
+VEML6070 I2C UV sensor example
+
+Copyright 2016 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/>.
+ *
+ *************************************************************************** */
+
+This example shows the support of the VEML6070 I2C UV sensor
+
+Periodic conversions (raw conversion value) are sent on UART0 using the
+following frame format :
+UV: 0x1b60
+
--- /dev/null
+/****************************************************************************
+ * apps/base/i2c_uv/main.c
+ *
+ * VEML6070 I2C UV sensor example
+ *
+ * Copyright 2016 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/i2c.h"
+#include "drivers/serial.h"
+#include "drivers/gpio.h"
+#include "extdrv/status_led.h"
+
+#include "extdrv/veml6070_uv_sensor.h"
+
+
+#define MODULE_VERSION 0x04
+#define MODULE_NAME "GPIO Demo Module"
+
+
+#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 */
+ { LPC_UART0_RX_PIO_0_1, LPC_IO_DIGITAL },
+ { LPC_UART0_TX_PIO_0_2, LPC_IO_DIGITAL },
+ /* I2C 0 */
+ { 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) },
+ ARRAY_LAST_PIO,
+};
+
+const struct pio status_led_green = LPC_GPIO_1_4;
+const struct pio status_led_red = LPC_GPIO_1_5;
+
+
+/***************************************************************************** */
+/* UV */
+
+/* The I2C UV light sensor is at addresses 0x70, 0x71 and 0x73 */
+/* Note : These are 8bits address */
+#define VEML6070_ADDR 0x70
+struct veml6070_sensor_config veml6070_sensor = {
+ .addr = VEML6070_ADDR,
+};
+
+void uv_config(int uart_num)
+{
+ int ret = 0;
+
+ /* UV sensor */
+ ret = veml6070_configure(&veml6070_sensor);
+ if (ret != 0) {
+ uprintf(uart_num, "UV config error: %d\n", ret);
+ }
+}
+
+void uv_display(int uart_num)
+{
+ uint16_t uv_raw = 0;
+ int ret = 0;
+
+ ret = veml6070_sensor_read(&veml6070_sensor, &uv_raw);
+ if (ret != 0) {
+ uprintf(uart_num, "UV read error: %d\n", ret);
+ } else {
+ uprintf(uart_num, "UV: 0x%04x\n", uv_raw);
+ }
+}
+
+
+
+/***************************************************************************** */
+void system_init()
+{
+ /* Stop the watchdog */
+ startup_watchdog_disable(); /* Do it right now, before it gets a chance to break in */
+ system_brown_out_detection_config(0); /* No ADC used */
+ 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);
+}
+
+
+
+/***************************************************************************** */
+int main(void)
+{
+ system_init();
+ uart_on(UART0, 115200, NULL);
+
+ i2c_on(I2C0, I2C_CLK_100KHz, I2C_MASTER);
+
+ /* Configure UV sensor */
+ uv_config(UART0);
+
+ while (1) {
+ chenillard(250);
+ uv_display(UART0);
+ }
+ return 0;
+}
+