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