diff --git a/cpu/x86/drivers/quarkX1000/i2c.c b/cpu/x86/drivers/quarkX1000/i2c.c index b16a79205..4e5669079 100644 --- a/cpu/x86/drivers/quarkX1000/i2c.c +++ b/cpu/x86/drivers/quarkX1000/i2c.c @@ -54,6 +54,15 @@ typedef enum { I2C_DIRECTION_WRITE } I2C_DIRECTION; +struct quarkX1000_i2c_config { + QUARKX1000_I2C_SPEED speed; + QUARKX1000_I2C_ADDR_MODE addressing_mode; + + quarkX1000_i2c_callback cb_rx; + quarkX1000_i2c_callback cb_tx; + quarkX1000_i2c_callback cb_err; +}; + struct i2c_internal_data { struct quarkX1000_i2c_config config; @@ -223,17 +232,15 @@ i2c_isr(void) return handled; } -int -quarkX1000_i2c_configure(struct quarkX1000_i2c_config *config) +void +quarkX1000_i2c_configure(QUARKX1000_I2C_SPEED speed, + QUARKX1000_I2C_ADDR_MODE addressing_mode) { uint32_t hcnt, lcnt; uint8_t ic_fs_spklen; - device.config.speed = config->speed; - device.config.addressing_mode = config->addressing_mode; - device.config.cb_rx = config->cb_rx; - device.config.cb_tx = config->cb_tx; - device.config.cb_err = config->cb_err; + device.config.speed = speed; + device.config.addressing_mode = addressing_mode; if (device.config.speed == QUARKX1000_I2C_SPEED_STANDARD) { lcnt = I2C_STD_LCNT; @@ -252,8 +259,16 @@ quarkX1000_i2c_configure(struct quarkX1000_i2c_config *config) /* Clear interrupts. */ read(QUARKX1000_IC_CLR_INTR); +} - return 0; +void +quarkX1000_i2c_set_callbacks(quarkX1000_i2c_callback rx, + quarkX1000_i2c_callback tx, + quarkX1000_i2c_callback err) +{ + device.config.cb_rx = rx; + device.config.cb_tx = tx; + device.config.cb_err = err; } static int diff --git a/cpu/x86/drivers/quarkX1000/i2c.h b/cpu/x86/drivers/quarkX1000/i2c.h index b5292524f..ed2db18fb 100644 --- a/cpu/x86/drivers/quarkX1000/i2c.h +++ b/cpu/x86/drivers/quarkX1000/i2c.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015, Intel Corporation. All rights reserved. + * Copyright (C) 2015-2016, Intel Corporation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -45,17 +45,12 @@ typedef enum { typedef void (*quarkX1000_i2c_callback)(void); -struct quarkX1000_i2c_config { - QUARKX1000_I2C_SPEED speed; - QUARKX1000_I2C_ADDR_MODE addressing_mode; - - quarkX1000_i2c_callback cb_rx; - quarkX1000_i2c_callback cb_tx; - quarkX1000_i2c_callback cb_err; -}; - int quarkX1000_i2c_init(void); -int quarkX1000_i2c_configure(struct quarkX1000_i2c_config *config); +void quarkX1000_i2c_configure(QUARKX1000_I2C_SPEED speed, + QUARKX1000_I2C_ADDR_MODE addressing_mode); +void quarkX1000_i2c_set_callbacks(quarkX1000_i2c_callback rx, + quarkX1000_i2c_callback tx, + quarkX1000_i2c_callback err); int quarkX1000_i2c_is_available(void); int quarkX1000_i2c_read(uint8_t *buf, uint8_t len, uint16_t addr); diff --git a/examples/galileo/README.md b/examples/galileo/README.md index ce4cb03a9..61e8ea713 100644 --- a/examples/galileo/README.md +++ b/examples/galileo/README.md @@ -21,10 +21,10 @@ GPIO ### GPIO Output (EXAMPLE=gpio-output) This application shows how to use the GPIO driver APIs to manipulate output -pins. This application sets the GPIO 4 pin as output pin and toggles its +pins. This application sets the GPIO 5 pin as output pin and toggles its state at every half second. -For a visual effect, you should wire shield pin IO1 to a led in a protoboard. +For a visual effect, you should wire shield pin IO2 to a led in a protoboard. Once the application is running, you should see a blinking LED. ### GPIO Input (EXAMPLE=gpio-input) diff --git a/examples/galileo/gpio-input.c b/examples/galileo/gpio-input.c index 8728d5088..196ea9193 100644 --- a/examples/galileo/gpio-input.c +++ b/examples/galileo/gpio-input.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015, Intel Corporation. All rights reserved. + * Copyright (C) 2015-2016, Intel Corporation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -33,16 +33,13 @@ #include "contiki.h" #include "sys/ctimer.h" -#include "galileo-pinmux.h" #include "gpio.h" -#include "i2c.h" #define PIN_OUTPUT 5 #define PIN_INPUT 6 static uint32_t value; static struct ctimer timer; -static struct quarkX1000_i2c_config i2c_config; PROCESS(gpio_input_process, "GPIO Input Process"); AUTOSTART_PROCESSES(&gpio_input_process); @@ -70,16 +67,6 @@ PROCESS_THREAD(gpio_input_process, ev, data) { PROCESS_BEGIN(); - i2c_config.speed = QUARKX1000_I2C_SPEED_STANDARD; - i2c_config.addressing_mode = QUARKX1000_I2C_ADDR_MODE_7BIT; - - quarkX1000_i2c_init(); - quarkX1000_i2c_configure(&i2c_config); - - /* use default pinmux configuration */ - galileo_pinmux_initialize(); - - quarkX1000_gpio_init(); quarkX1000_gpio_config(PIN_OUTPUT, QUARKX1000_GPIO_OUT); quarkX1000_gpio_config(PIN_INPUT, QUARKX1000_GPIO_IN); diff --git a/examples/galileo/gpio-interrupt.c b/examples/galileo/gpio-interrupt.c index 149279f6f..04fb4cc1b 100644 --- a/examples/galileo/gpio-interrupt.c +++ b/examples/galileo/gpio-interrupt.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015, Intel Corporation. All rights reserved. + * Copyright (C) 2015-2016, Intel Corporation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -34,14 +34,11 @@ #include "sys/ctimer.h" #include "gpio.h" -#include "i2c.h" -#include "galileo-pinmux.h" #define PIN_OUTPUT 5 #define PIN_INTR 6 static struct ctimer timer; -static struct quarkX1000_i2c_config i2c_config; PROCESS(gpio_interrupt_process, "GPIO Interrupt Process"); AUTOSTART_PROCESSES(&gpio_interrupt_process); @@ -66,16 +63,6 @@ PROCESS_THREAD(gpio_interrupt_process, ev, data) { PROCESS_BEGIN(); - i2c_config.speed = QUARKX1000_I2C_SPEED_STANDARD; - i2c_config.addressing_mode = QUARKX1000_I2C_ADDR_MODE_7BIT; - - quarkX1000_i2c_init(); - quarkX1000_i2c_configure(&i2c_config); - - /* use default pinmux configuration */ - galileo_pinmux_initialize(); - - quarkX1000_gpio_init(); quarkX1000_gpio_config(PIN_OUTPUT, QUARKX1000_GPIO_OUT); quarkX1000_gpio_config(PIN_INTR, QUARKX1000_GPIO_INT | QUARKX1000_GPIO_ACTIVE_HIGH | QUARKX1000_GPIO_EDGE); diff --git a/examples/galileo/gpio-output.c b/examples/galileo/gpio-output.c index 39a92516f..4dad7d684 100644 --- a/examples/galileo/gpio-output.c +++ b/examples/galileo/gpio-output.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015, Intel Corporation. All rights reserved. + * Copyright (C) 2015-2016, Intel Corporation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -35,7 +35,7 @@ #include "gpio.h" -#define PIN 4 /* IO1 */ +#define PIN 5 /* IO2 */ static uint32_t value; static struct ctimer timer; @@ -57,7 +57,6 @@ PROCESS_THREAD(gpio_output_process, ev, data) { PROCESS_BEGIN(); - quarkX1000_gpio_init(); quarkX1000_gpio_config(PIN, QUARKX1000_GPIO_OUT); quarkX1000_gpio_clock_enable(); diff --git a/examples/galileo/i2c-LSM9DS0.c b/examples/galileo/i2c-LSM9DS0.c index e5a47c458..03d61a2a4 100644 --- a/examples/galileo/i2c-LSM9DS0.c +++ b/examples/galileo/i2c-LSM9DS0.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015, Intel Corporation. All rights reserved. + * Copyright (C) 2015-2016, Intel Corporation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -34,7 +34,6 @@ #include "contiki.h" #include "sys/ctimer.h" -#include "galileo-pinmux.h" #include "i2c.h" #define LSM9DS0_I2C_ADDR 0x6A @@ -44,7 +43,6 @@ static uint8_t tx_data = WHO_AM_I_ADDR; static uint8_t rx_data = 0; static struct ctimer timer; -static struct quarkX1000_i2c_config cfg; PROCESS(i2c_lsm9ds0_process, "I2C LSM9DS0 Who Am I Process"); AUTOSTART_PROCESSES(&i2c_lsm9ds0_process); @@ -84,19 +82,7 @@ PROCESS_THREAD(i2c_lsm9ds0_process, ev, data) { PROCESS_BEGIN(); - cfg.speed = QUARKX1000_I2C_SPEED_STANDARD; - cfg.addressing_mode = QUARKX1000_I2C_ADDR_MODE_7BIT; - - quarkX1000_i2c_init(); - quarkX1000_i2c_configure(&cfg); - - galileo_pinmux_initialize(); - - cfg.cb_rx = rx; - cfg.cb_tx = tx; - cfg.cb_err = err; - - quarkX1000_i2c_configure(&cfg); + quarkX1000_i2c_set_callbacks(rx, tx, err); ctimer_set(&timer, CLOCK_SECOND * 5, timeout, NULL); diff --git a/platform/galileo/README.md b/platform/galileo/README.md index b99ad7d65..815b09011 100644 --- a/platform/galileo/README.md +++ b/platform/galileo/README.md @@ -30,6 +30,9 @@ Device drivers: * Real-Time Clock (RTC) * UART * Ethernet + * I2C + * GPIO (default pinmux configuration is listed in + platform/galileo/drivers/galileo-pinmux.c) Contiki APIs: * Clock module diff --git a/platform/galileo/contiki-main.c b/platform/galileo/contiki-main.c index bb6d0c5cb..141ad2a51 100644 --- a/platform/galileo/contiki-main.c +++ b/platform/galileo/contiki-main.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015, Intel Corporation. All rights reserved. + * Copyright (C) 2015-2016, Intel Corporation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -34,6 +34,9 @@ #include "contiki-net.h" #include "cpu.h" #include "eth-conf.h" +#include "galileo-pinmux.h" +#include "gpio.h" +#include "i2c.h" #include "interrupt.h" #include "shared-isr.h" #include "uart.h" @@ -56,6 +59,15 @@ main(void) printf("Starting Contiki\n"); + quarkX1000_i2c_init(); + quarkX1000_i2c_configure(QUARKX1000_I2C_SPEED_STANDARD, + QUARKX1000_I2C_ADDR_MODE_7BIT); + /* use default pinmux configuration */ + if(galileo_pinmux_initialize() < 0) { + fprintf(stderr, "Failed to initialize pinmux\n"); + } + quarkX1000_gpio_init(); + ENABLE_IRQ(); process_init(); diff --git a/platform/galileo/drivers/galileo-pinmux.c b/platform/galileo/drivers/galileo-pinmux.c index c66036ea2..3059bdb36 100644 --- a/platform/galileo/drivers/galileo-pinmux.c +++ b/platform/galileo/drivers/galileo-pinmux.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015, Intel Corporation. All rights reserved. + * Copyright (C) 2015-2016, Intel Corporation. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions