Blame view

RIOT/drivers/io1_xplained/io1_xplained.c 2.27 KB
a752c7ab   elopes   add first test an...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
  /*
   * Copyright (C) 2016 Inria
   *
   * This file is subject to the terms and conditions of the GNU Lesser
   * General Public License v2.1. See the file LICENSE in the top level
   * directory for more details.
   */
  
  /**
   * @ingroup     drivers_io1_xplained
   * @{
   *
   * @file
   * @brief       Device driver implementation for the Atmel IO1 Xplained extension
   *
   * @author      Alexandre Abadie <alexandre.abadie@inria.fr>
   *
   * @}
   */
  
  #include "log.h"
  #include "io1_xplained.h"
  #include "io1_xplained_internals.h"
  #include "at30tse75x.h"
  #include "periph/i2c.h"
  #include "periph/gpio.h"
  
  /*---------------------------------------------------------------------------*
   *                          IO1 Xplained Core API                            *
   *---------------------------------------------------------------------------*/
  
  int io1_xplained_init(io1_xplained_t *dev, const io1_xplained_params_t *params)
  {
      dev->params = *params;
  
      /* Initialize I2C interface */
      if (at30tse75x_init(&dev->temp,
                          I2C_DEV(0),
                          I2C_SPEED_NORMAL, (TEMPERATURE_BASE_ADDR | dev->params.addr)) < 0) {
          LOG_ERROR("Cannot initialize temperature sensor.\n");
          return -IO1_XPLAINED_NOTEMP;
      }
  
      /* Use maximum resolution */
      at30tse75x_set_resolution(&dev->temp, AT30TSE75X_RESOLUTION_12BIT);
  
      if (gpio_init(IO1_LED_PIN, GPIO_OUT) < 0) {
          LOG_ERROR("GPIO LED not enabled\n");
          return -IO1_XPLAINED_NOLED;
      }
  
      if (gpio_init(IO1_GPIO1_PIN, GPIO_OUT) < 0) {
          LOG_ERROR("GPIO1 not enabled\n");
          return -IO1_XPLAINED_NOGPIO1;
      }
  
      if (gpio_init(IO1_GPIO2_PIN, GPIO_OUT) < 0) {
          LOG_ERROR("GPIO2 not enabled\n");
          return -IO1_XPLAINED_NOGPIO2;
      }
  
      LOG_DEBUG("IO1 Xplained extension initialized!\n");
  
      return IO1_XPLAINED_OK;
  }
  
  int io1_xplained_read_temperature(const io1_xplained_t *dev, float *temperature)
  {
      if (at30tse75x_get_temperature(&dev->temp, temperature) < 0) {
          LOG_ERROR("Cannot read temperature sensor.\n");
          return -IO1_XPLAINED_READ_ERR;
      }
      return IO1_XPLAINED_READ_OK;
  }
  
  void io1_xplained_set_led(void)
  {
      gpio_set(IO1_LED_PIN);
  }
  
  void io1_xplained_clear_led(void)
  {
      gpio_clear(IO1_LED_PIN);
  }
  
  void io1_xplained_toggle_led(void)
  {
      gpio_toggle(IO1_LED_PIN);
  }