[270] | 1 | /*
|
---|
| 2 | *
|
---|
| 3 | */
|
---|
| 4 | #ifndef _ARDUINO_H_
|
---|
| 5 | #define _ARDUINO_H_
|
---|
| 6 |
|
---|
| 7 | #include <stdint.h>
|
---|
| 8 | #include <stdio.h>
|
---|
| 9 | #include <stdlib.h>
|
---|
| 10 | #include <string.h>
|
---|
| 11 | #include <time.h>
|
---|
| 12 | #include <analogin_api.h>
|
---|
| 13 | #include <analogout_api.h>
|
---|
| 14 | #include <buffer.h>
|
---|
| 15 | #include <can_api.h>
|
---|
| 16 | #include <dma_api.h>
|
---|
| 17 | #include <ethernet_api.h>
|
---|
| 18 | #include <gpio_api.h>
|
---|
| 19 | #include <gpio_irq_api.h>
|
---|
| 20 | #include <i2c_api.h>
|
---|
| 21 | #include <lp_ticker_api.h>
|
---|
| 22 | #include <pinmap.h>
|
---|
| 23 | #include <port_api.h>
|
---|
| 24 | #include <pwmout_api.h>
|
---|
| 25 | #include <rtc_api.h>
|
---|
| 26 | #include <serial_api.h>
|
---|
| 27 | #include <sleep_api.h>
|
---|
| 28 | #include <spi_api.h>
|
---|
| 29 | #include <ticker_api.h>
|
---|
| 30 | #include <us_ticker_api.h>
|
---|
| 31 | #include <wait_api.h>
|
---|
| 32 | #include "diskio.h"
|
---|
| 33 | #include "ff.h"
|
---|
| 34 |
|
---|
| 35 | #ifndef bool
|
---|
| 36 | #define bool int
|
---|
| 37 | #endif
|
---|
| 38 | #ifndef true
|
---|
| 39 | #define true 1
|
---|
| 40 | #endif
|
---|
| 41 | #ifndef false
|
---|
| 42 | #define false 0
|
---|
| 43 | #endif
|
---|
| 44 |
|
---|
| 45 | typedef unsigned char byte;
|
---|
| 46 |
|
---|
| 47 | void arduino_init(void);
|
---|
| 48 |
|
---|
| 49 | typedef enum pintype_e {
|
---|
| 50 | pintype_none,
|
---|
| 51 | pintype_gpio,
|
---|
| 52 | pintype_dac,
|
---|
| 53 | pintype_pwmout,
|
---|
| 54 | pintype_analogin,
|
---|
| 55 | } PinType;
|
---|
| 56 |
|
---|
| 57 | struct pin_node {
|
---|
| 58 | struct pin_node *next;
|
---|
| 59 | PinName pin;
|
---|
| 60 | PinType type;
|
---|
| 61 | union {
|
---|
| 62 | gpio_t gpio;
|
---|
| 63 | #if DEVICE_ANALOGOUT
|
---|
| 64 | dac_t dac;
|
---|
| 65 | #endif
|
---|
| 66 | pwmout_t pwmout;
|
---|
| 67 | analogin_t analogin;
|
---|
| 68 | };
|
---|
| 69 | uint32_t period;
|
---|
| 70 | uint32_t pulsewidth;
|
---|
| 71 | int min;
|
---|
| 72 | int max;
|
---|
| 73 | };
|
---|
| 74 |
|
---|
| 75 | struct pin_node *get_pin(PinType type, PinName pinno);
|
---|
| 76 | PinType get_pin_type(PinName pin);
|
---|
| 77 |
|
---|
| 78 | #define DEFAULT 0
|
---|
| 79 | #define INTERNAL 1
|
---|
| 80 | #define EXTERNAL 2
|
---|
| 81 | #define RAW12BIT 3
|
---|
| 82 |
|
---|
| 83 | void analogReference(int type);
|
---|
| 84 | void setPinModeDac(int pin);
|
---|
| 85 | void tone(int pin, int frequency, int duration);
|
---|
| 86 | void noTone(int pin);
|
---|
| 87 | void randomSeed(long seed);
|
---|
| 88 | long arduino_random(long min, long max);
|
---|
| 89 |
|
---|
| 90 | typedef enum sci_port {
|
---|
| 91 | SCI_USB0,
|
---|
| 92 | SCI_SCI0P2x,
|
---|
| 93 | SCI_SCI2B,
|
---|
| 94 | SCI_SCI6B,
|
---|
| 95 | SCI_SCI2A,
|
---|
| 96 | } SCI_PORT;
|
---|
| 97 |
|
---|
| 98 | bool portToPins(SCI_PORT port, PinName *txpin, PinName *rxpin);
|
---|
| 99 |
|
---|
| 100 | extern serial_t *Serial;
|
---|
| 101 | extern serial_t *Serial1; /*1:Serial1*/
|
---|
| 102 | extern serial_t *Serial2; /*2:Serial3*/
|
---|
| 103 | extern serial_t *Serial3; /*3:Serial2*/
|
---|
| 104 | extern serial_t *Serial4; /*4:Serial6*/
|
---|
| 105 | extern serial_t *Serial5; /*5:Serial7*/
|
---|
| 106 |
|
---|
| 107 | int serial_write(serial_t *serial, const unsigned char *c, int len);
|
---|
| 108 | int serial_print(serial_t *serial, const char *c);
|
---|
| 109 | int serial_println(serial_t *serial, const char *c);
|
---|
| 110 |
|
---|
| 111 | extern i2c_t Wire1;
|
---|
| 112 | extern i2c_t Wire2;
|
---|
| 113 | extern i2c_t Wire3;
|
---|
| 114 | extern i2c_t Wire4;
|
---|
| 115 | extern i2c_t Wire5;
|
---|
| 116 |
|
---|
| 117 | typedef struct File {
|
---|
| 118 | FIL fp;
|
---|
| 119 | } File;
|
---|
| 120 |
|
---|
| 121 | #define FILE_READ 0x01
|
---|
| 122 | #define FILE_WRITE 0x02
|
---|
| 123 |
|
---|
| 124 | int file_write(File *fd, unsigned char *str, int len);
|
---|
| 125 | void file_close(File *fd);
|
---|
| 126 | int file_size(File *fd);
|
---|
| 127 | int file_position(File *fd);
|
---|
| 128 | void file_flush(File *fd);
|
---|
| 129 | bool file_seek(File *fd, int pos);
|
---|
| 130 | int file_read(File *fd);
|
---|
| 131 |
|
---|
| 132 | typedef struct SD {
|
---|
| 133 | DSTATUS dst;
|
---|
| 134 | BYTE type;
|
---|
| 135 | FATFS FatFs;
|
---|
| 136 | } SD;
|
---|
| 137 |
|
---|
| 138 | extern SD Sd;
|
---|
| 139 |
|
---|
| 140 | bool SD_begin();
|
---|
| 141 | bool SD_open(File *file, const char *path, int mode);
|
---|
| 142 | bool SD_rmdir(const char *path);
|
---|
| 143 | bool SD_rename(const char *path1, const char *path2);
|
---|
| 144 | bool SD_remove(const char *path);
|
---|
| 145 | bool SD_exists(const char *path);
|
---|
| 146 | bool SD_mkdir(const char *path);
|
---|
| 147 |
|
---|
| 148 | typedef struct FILEEEP {
|
---|
| 149 | FIL fp;
|
---|
| 150 | } FILEEEP;
|
---|
| 151 |
|
---|
| 152 | int EEP_fopen(FILEEEP *fp, const char *str, char mode);
|
---|
| 153 | int EEP_fwrite(FILEEEP *fp, byte *data, int *len);
|
---|
| 154 | int EEP_fread(FILEEEP *fp);
|
---|
| 155 | void EEP_fclose(FILEEEP *fp);
|
---|
| 156 | int EEP_fseek(FILEEEP *fp, int pos, int mode);
|
---|
| 157 | int EEP_ffilesize(const char *str);
|
---|
| 158 | bool EEP_fEof(FILEEEP *fp);
|
---|
| 159 | int EEP_fexist(const char *path);
|
---|
| 160 | int EEP_fcopy(const char *src, const char *dst);
|
---|
| 161 | int EEP_fdelete(const char *path);
|
---|
| 162 |
|
---|
| 163 | #define EEP_SEEKTOP 1
|
---|
| 164 | #define EEP_SEEKCUR 2
|
---|
| 165 | #define EEP_SEEKEND 3
|
---|
| 166 |
|
---|
| 167 | #define EEP_READ 0x01
|
---|
| 168 | #define EEP_WRITE 0x02
|
---|
| 169 | #define EEP_APPEND 0x4
|
---|
| 170 |
|
---|
| 171 | uint8_t EEPROM_write(int addr, uint8_t data);
|
---|
| 172 | uint8_t EEPROM_read(int addr);
|
---|
| 173 |
|
---|
| 174 | #define REBOOT_USERAPP 1
|
---|
| 175 | void system_reboot(int mode);
|
---|
| 176 | int fileloader(const char *progVer, const char *binVer);
|
---|
| 177 |
|
---|
| 178 | extern volatile char ProgVer[];
|
---|
| 179 | extern char RubyFilename[64];
|
---|
| 180 | extern char ExeFilename[64];
|
---|
| 181 |
|
---|
| 182 | #endif /* _ARDUINO_H_ */
|
---|