Initial version

This commit is contained in:
Sandeep Mistry
2018-06-28 12:55:29 +02:00
parent 763916f80a
commit 48ebd39cfd
34 changed files with 4216 additions and 10 deletions

View File

@@ -0,0 +1,52 @@
/*
This file is part of the MKR WiFi 1010 firmware.
Copyright (C) 2018 Arduino AG (http://www.arduino.cc/)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef ARDUINO_H
#define ARDUINO_H
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#ifdef __cplusplus
extern "C"{
#endif // __cplusplus
// system functions
void init(void);
// sketch
void setup(void);
void loop(void);
#ifdef __cplusplus
} // extern "C"
#endif
#ifdef __cplusplus
#include "WMath.h"
#endif
#include "delay.h"
#include "wiring_digital.h"
#include "wiring_analog.h"
#endif // ARDUINO_H

View File

@@ -0,0 +1,74 @@
/*
This file is part of the MKR WiFi 1010 firmware.
Copyright (C) 2018 Arduino AG (http://www.arduino.cc/)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <driver/gpio.h>
#include "wiring_digital.h"
#include "WInterrupts.h"
static voidFuncPtr callbacksInt[GPIO_NUM_MAX] = { NULL };
void IRAM_ATTR gpioInterruptHandler(void* arg)
{
uint32_t pin = (uint32_t)arg;
if (callbacksInt[pin]) {
callbacksInt[pin]();
}
}
void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode)
{
callbacksInt[pin] = callback;
switch (mode) {
case LOW:
gpio_set_intr_type((gpio_num_t)pin, GPIO_INTR_LOW_LEVEL);
gpio_wakeup_enable((gpio_num_t)pin, GPIO_INTR_LOW_LEVEL);
break;
case HIGH:
gpio_set_intr_type((gpio_num_t)pin, GPIO_INTR_HIGH_LEVEL);
gpio_wakeup_enable((gpio_num_t)pin, GPIO_INTR_HIGH_LEVEL);
break;
case CHANGE:
gpio_set_intr_type((gpio_num_t)pin, GPIO_INTR_ANYEDGE);
break;
case FALLING:
gpio_set_intr_type((gpio_num_t)pin, GPIO_INTR_NEGEDGE);
break;
case RISING:
gpio_set_intr_type((gpio_num_t)pin, GPIO_INTR_POSEDGE);
break;
default:
gpio_set_intr_type((gpio_num_t)pin, GPIO_INTR_DISABLE);
break;
}
gpio_install_isr_service(ESP_INTR_FLAG_LEVEL3);
gpio_isr_handler_add((gpio_num_t)pin, gpioInterruptHandler, (void*)pin);
gpio_intr_enable((gpio_num_t)pin);
}

View File

@@ -0,0 +1,43 @@
/*
This file is part of the MKR WiFi 1010 firmware.
Copyright (C) 2018 Arduino AG (http://www.arduino.cc/)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _WIRING_INTERRUPTS_
#define _WIRING_INTERRUPTS_
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
// #define LOW 0
// #define HIGH 1
#define CHANGE 2
#define FALLING 3
#define RISING 4
typedef void (*voidFuncPtr)(void);
void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,33 @@
/*
This file is part of the MKR WiFi 1010 firmware.
Copyright (C) 2018 Arduino AG (http://www.arduino.cc/)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
extern "C" {
#include <esp_system.h>
}
#include "WMath.h"
extern long random(long howbig)
{
if(howbig == 0) {
return 0;
}
return esp_random() % howbig;
}

View File

@@ -0,0 +1,33 @@
/*
This file is part of the MKR WiFi 1010 firmware.
Copyright (C) 2018 Arduino AG (http://www.arduino.cc/)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _WIRING_MATH_
#define _WIRING_MATH_
#ifdef __cplusplus
extern "C" {
#endif
extern long random(long);
#ifdef __cplusplus
}
#endif
#endif /* _WIRING_MATH_ */

View File

@@ -0,0 +1,33 @@
/*
This file is part of the MKR WiFi 1010 firmware.
Copyright (C) 2018 Arduino AG (http://www.arduino.cc/)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include "delay.h"
unsigned long millis()
{
return xTaskGetTickCount() * portTICK_PERIOD_MS;
}
void delay(uint32_t ms)
{
vTaskDelay(ms / portTICK_PERIOD_MS);
}

View File

@@ -0,0 +1,37 @@
/*
This file is part of the MKR WiFi 1010 firmware.
Copyright (C) 2018 Arduino AG (http://www.arduino.cc/)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef DELAY_H
#define DELAY_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
extern unsigned long millis();
extern void delay(uint32_t ms);
#ifdef __cplusplus
}
#endif
#endif // DELAY_H

View File

@@ -0,0 +1,40 @@
/*
This file is part of the MKR WiFi 1010 firmware.
Copyright (C) 2018 Arduino AG (http://www.arduino.cc/)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#define ARDUINO_MAIN
#include "Arduino.h"
void arduino_main(void*) {
init();
setup();
while (1) {
loop();
}
}
extern "C" {
void app_main() {
xTaskCreatePinnedToCore(arduino_main, "arduino", 8192, NULL, 1, NULL, 1);
}
}

View File

@@ -0,0 +1,26 @@
/*
This file is part of the MKR WiFi 1010 firmware.
Copyright (C) 2018 Arduino AG (http://www.arduino.cc/)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <nvs_flash.h>
#include "Arduino.h"
void init() {
nvs_flash_init();
}

View File

@@ -0,0 +1,45 @@
/*
This file is part of the MKR WiFi 1010 firmware.
Copyright (C) 2018 Arduino AG (http://www.arduino.cc/)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <driver/ledc.h>
#include "wiring_analog.h"
void analogWrite(uint32_t pin, uint32_t value)
{
periph_module_enable(PERIPH_LEDC_MODULE);
ledc_timer_config_t timerConf = {
.bit_num = LEDC_TIMER_10_BIT,
.freq_hz = 1000,
.speed_mode = LEDC_HIGH_SPEED_MODE,
.timer_num = (pin / 7),
};
ledc_timer_config(&timerConf);
ledc_channel_config_t ledc_conf = {
.channel = (pin % 7),
.duty = (value << 2),
.gpio_num = pin,
.intr_type = LEDC_INTR_DISABLE,
.speed_mode = LEDC_HIGH_SPEED_MODE,
.timer_sel = (pin / 7)
};
ledc_channel_config(&ledc_conf);
}

View File

@@ -0,0 +1,35 @@
/*
This file is part of the MKR WiFi 1010 firmware.
Copyright (C) 2018 Arduino AG (http://www.arduino.cc/)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef WIRING_ANALOG_H
#define WIRING_ANALOG_H
#include "Arduino.h"
#ifdef __cplusplus
extern "C" {
#endif
extern void analogWrite(uint32_t pin, uint32_t value);
#ifdef __cplusplus
}
#endif
#endif // WIRING_ANALOG_H

View File

@@ -0,0 +1,44 @@
/*
This file is part of the MKR WiFi 1010 firmware.
Copyright (C) 2018 Arduino AG (http://www.arduino.cc/)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <driver/gpio.h>
#include "wiring_digital.h"
void pinMode(uint32_t pin, uint32_t mode)
{
switch (mode) {
case INPUT:
gpio_set_direction((gpio_num_t)pin, GPIO_MODE_INPUT);
gpio_set_pull_mode((gpio_num_t)pin, GPIO_FLOATING);
break;
case OUTPUT:
gpio_set_direction((gpio_num_t)pin, GPIO_MODE_OUTPUT);
gpio_set_pull_mode((gpio_num_t)pin, GPIO_FLOATING);
break;
}
PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[pin], PIN_FUNC_GPIO);
}
void digitalWrite(uint32_t pin, uint32_t val)
{
gpio_set_level((gpio_num_t)pin, val);
}

View File

@@ -0,0 +1,43 @@
/*
This file is part of the MKR WiFi 1010 firmware.
Copyright (C) 2018 Arduino AG (http://www.arduino.cc/)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef WIRING_DIGITAL_H
#define WIRING_DIGITAL_H
#include "Arduino.h"
#ifdef __cplusplus
extern "C" {
#endif
#define LOW 0x00
#define HIGH 0x01
#define INPUT 0x00
#define OUTPUT 0x01
extern void pinMode(uint32_t pin, uint32_t mode);
extern void digitalWrite(uint32_t pin, uint32_t val);
#ifdef __cplusplus
}
#endif
#endif // WIRING_DIGITAL_H