2016-09-02 09:13:51 +02:00
|
|
|
/*
|
|
|
|
* 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 tests
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief Test application for the Atmel IO1 Xplained extension
|
|
|
|
*
|
|
|
|
* @author Alexandre Abadie <alexandre.abadie@inria.fr>
|
|
|
|
*
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
2021-12-09 10:22:12 +01:00
|
|
|
#include "timex.h"
|
|
|
|
#include "ztimer.h"
|
2016-09-02 09:13:51 +02:00
|
|
|
#include "board.h"
|
|
|
|
|
2018-04-16 16:55:10 +02:00
|
|
|
#include "periph/gpio.h"
|
|
|
|
|
|
|
|
#include "at30tse75x.h"
|
2018-04-16 17:37:05 +02:00
|
|
|
#include "sdcard_spi.h"
|
2018-04-16 16:55:10 +02:00
|
|
|
#include "io1_xplained.h"
|
|
|
|
#include "io1_xplained_params.h"
|
|
|
|
|
2021-12-09 10:22:12 +01:00
|
|
|
#define DELAY_1S (1U * MS_PER_SEC) /* 1 seconds delay between each test */
|
2016-09-02 09:13:51 +02:00
|
|
|
|
2018-04-16 17:37:05 +02:00
|
|
|
static io1_xplained_t dev;
|
|
|
|
|
|
|
|
static void _sd_card_cid(void)
|
|
|
|
{
|
|
|
|
puts("SD Card CID info:");
|
|
|
|
printf("MID: %d\n", dev.sdcard.cid.MID);
|
|
|
|
printf("OID: %c%c\n", dev.sdcard.cid.OID[0], dev.sdcard.cid.OID[1]);
|
|
|
|
printf("PNM: %c%c%c%c%c\n",
|
|
|
|
dev.sdcard.cid.PNM[0], dev.sdcard.cid.PNM[1], dev.sdcard.cid.PNM[2],
|
|
|
|
dev.sdcard.cid.PNM[3], dev.sdcard.cid.PNM[4]);
|
2018-08-01 23:00:51 +02:00
|
|
|
printf("PRV: %u\n", dev.sdcard.cid.PRV);
|
|
|
|
printf("PSN: %" PRIu32 "\n", dev.sdcard.cid.PSN);
|
|
|
|
printf("MDT: %u\n", dev.sdcard.cid.MDT);
|
|
|
|
printf("CRC: %u\n", dev.sdcard.cid.CID_CRC);
|
2018-04-16 17:37:05 +02:00
|
|
|
puts("+----------------------------------------+\n");
|
|
|
|
}
|
|
|
|
|
2016-09-02 09:13:51 +02:00
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
float temperature;
|
|
|
|
|
2019-09-14 15:47:10 +02:00
|
|
|
puts("IO1 Xplained extension test application\n");
|
2017-03-23 14:19:52 +01:00
|
|
|
puts("+-------------Initializing------------+\n");
|
2016-09-02 09:13:51 +02:00
|
|
|
|
2017-03-23 14:19:52 +01:00
|
|
|
if (io1_xplained_init(&dev, &io1_xplained_params[0]) != IO1_XPLAINED_OK) {
|
2016-09-02 09:13:51 +02:00
|
|
|
puts("[Error] Cannot initialize the IO1 Xplained extension\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-03-23 14:19:52 +01:00
|
|
|
puts("Initialization successful");
|
|
|
|
puts("\n+--------Starting tests --------+");
|
2016-09-02 09:13:51 +02:00
|
|
|
while (1) {
|
|
|
|
/* Get temperature in degrees celsius */
|
2018-04-16 16:55:10 +02:00
|
|
|
at30tse75x_get_temperature(&dev.temp, &temperature);
|
2019-09-01 15:16:32 +02:00
|
|
|
printf("Temperature [°C]: %i.%03u\n"
|
2018-04-16 16:55:10 +02:00
|
|
|
"+-------------------------------------+\n",
|
2019-09-01 15:16:32 +02:00
|
|
|
(int)temperature,
|
|
|
|
(unsigned)((temperature - (int)temperature) * 1000));
|
2021-12-09 10:22:12 +01:00
|
|
|
ztimer_sleep(ZTIMER_MSEC, DELAY_1S);
|
2016-09-02 09:13:51 +02:00
|
|
|
|
2018-04-16 17:37:05 +02:00
|
|
|
/* Card detect pin is inverted */
|
|
|
|
if (!gpio_read(IO1_SDCARD_SPI_PARAM_DETECT)) {
|
|
|
|
_sd_card_cid();
|
2021-12-09 10:22:12 +01:00
|
|
|
ztimer_sleep(ZTIMER_MSEC, DELAY_1S);
|
2018-04-16 17:37:05 +02:00
|
|
|
}
|
|
|
|
|
2018-04-17 10:10:55 +02:00
|
|
|
uint16_t light;
|
|
|
|
io1_xplained_read_light_level(&light);
|
|
|
|
printf("Light level: %i\n"
|
|
|
|
"+-------------------------------------+\n",
|
|
|
|
light);
|
2021-12-09 10:22:12 +01:00
|
|
|
ztimer_sleep(ZTIMER_MSEC, DELAY_1S);
|
2018-04-17 10:10:55 +02:00
|
|
|
|
2016-09-02 09:13:51 +02:00
|
|
|
/* set led */
|
2018-04-16 16:55:10 +02:00
|
|
|
gpio_set(IO1_LED_PIN);
|
2021-12-09 10:22:12 +01:00
|
|
|
ztimer_sleep(ZTIMER_MSEC, DELAY_1S);
|
2016-09-02 09:13:51 +02:00
|
|
|
|
|
|
|
/* clear led */
|
2018-04-16 16:55:10 +02:00
|
|
|
gpio_clear(IO1_LED_PIN);
|
2021-12-09 10:22:12 +01:00
|
|
|
ztimer_sleep(ZTIMER_MSEC, DELAY_1S);
|
2016-09-02 09:13:51 +02:00
|
|
|
|
|
|
|
/* toggle led */
|
2018-04-16 16:55:10 +02:00
|
|
|
gpio_toggle(IO1_LED_PIN);
|
2021-12-09 10:22:12 +01:00
|
|
|
ztimer_sleep(ZTIMER_MSEC, DELAY_1S);
|
2016-09-02 09:13:51 +02:00
|
|
|
|
|
|
|
/* toggle led again */
|
2018-04-16 16:55:10 +02:00
|
|
|
gpio_toggle(IO1_LED_PIN);
|
2021-12-09 10:22:12 +01:00
|
|
|
ztimer_sleep(ZTIMER_MSEC, DELAY_1S);
|
2016-09-02 09:13:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|