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