Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit06df3bb

Browse files
committed
[ArduinoAPI] initial porting
1 parent2663be1 commit06df3bb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+482
-3677
lines changed

‎cores/arduino/Arduino.h‎

Lines changed: 5 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -20,47 +20,16 @@
2020
#ifndefArduino_h
2121
#defineArduino_h
2222

23-
#include<stdlib.h>
24-
#include<stdbool.h>
25-
#include<string.h>
26-
#include<math.h>
23+
#include"api/ArduinoAPI.h"
2724

2825
#include<avr/pgmspace.h>
2926
#include<avr/io.h>
3027
#include<avr/interrupt.h>
3128

32-
#include"binary.h"
33-
3429
#ifdef__cplusplus
3530
extern"C"{
3631
#endif
3732

38-
voidyield(void);
39-
40-
#defineHIGH 0x1
41-
#defineLOW 0x0
42-
43-
#defineINPUT 0x0
44-
#defineOUTPUT 0x1
45-
#defineINPUT_PULLUP 0x2
46-
47-
#definePI 3.1415926535897932384626433832795
48-
#defineHALF_PI 1.5707963267948966192313216916398
49-
#defineTWO_PI 6.283185307179586476925286766559
50-
#defineDEG_TO_RAD 0.017453292519943295769236907684886
51-
#defineRAD_TO_DEG 57.295779513082320876798154814105
52-
#defineEULER 2.718281828459045235360287471352
53-
54-
#defineSERIAL 0x0
55-
#defineDISPLAY 0x1
56-
57-
#defineLSBFIRST 0
58-
#defineMSBFIRST 1
59-
60-
#defineCHANGE 1
61-
#defineFALLING 2
62-
#defineRISING 3
63-
6433
#if defined(__AVR_ATtiny24__)|| defined(__AVR_ATtiny44__)|| defined(__AVR_ATtiny84__)
6534
#defineDEFAULT 0
6635
#defineEXTERNAL 1
@@ -84,75 +53,18 @@ void yield(void);
8453
#defineEXTERNAL 0
8554
#endif
8655

87-
// undefine stdlib's abs if encountered
88-
#ifdefabs
89-
#undef abs
90-
#endif
91-
92-
#definemin(a,b) ((a)<(b)?(a):(b))
93-
#definemax(a,b) ((a)>(b)?(a):(b))
94-
#defineabs(x) ((x)>0?(x):-(x))
95-
#defineconstrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
96-
#defineround(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
97-
#defineradians(deg) ((deg)*DEG_TO_RAD)
98-
#definedegrees(rad) ((rad)*RAD_TO_DEG)
99-
#definesq(x) ((x)*(x))
100-
10156
#defineinterrupts() sei()
10257
#definenoInterrupts() cli()
10358

10459
#defineclockCyclesPerMicrosecond() ( F_CPU / 1000000L )
10560
#defineclockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
10661
#definemicrosecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() )
10762

108-
#definelowByte(w) ((uint8_t) ((w) & 0xff))
109-
#definehighByte(w) ((uint8_t) ((w) >> 8))
110-
111-
#definebitRead(value,bit) (((value) >> (bit)) & 0x01)
112-
#definebitSet(value,bit) ((value) |= (1UL << (bit)))
113-
#definebitClear(value,bit) ((value) &= ~(1UL << (bit)))
114-
#definebitWrite(value,bit,bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
115-
11663
// avr-libc defines _NOP() since 1.6.2
11764
#ifndef_NOP
11865
#define_NOP() do { __asm__ volatile ("nop"); } while (0)
11966
#endif
12067

121-
typedefunsignedintword;
122-
123-
#definebit(b) (1UL << (b))
124-
125-
typedefboolboolean;
126-
typedefuint8_tbyte;
127-
128-
voidinit(void);
129-
voidinitVariant(void);
130-
131-
intatexit(void (*func)()) __attribute__((weak));
132-
133-
voidpinMode(uint8_t,uint8_t);
134-
voiddigitalWrite(uint8_t,uint8_t);
135-
intdigitalRead(uint8_t);
136-
intanalogRead(uint8_t);
137-
voidanalogReference(uint8_tmode);
138-
voidanalogWrite(uint8_t,int);
139-
140-
unsigned longmillis(void);
141-
unsigned longmicros(void);
142-
voiddelay(unsigned long);
143-
voiddelayMicroseconds(unsignedintus);
144-
unsigned longpulseIn(uint8_tpin,uint8_tstate,unsigned longtimeout);
145-
unsigned longpulseInLong(uint8_tpin,uint8_tstate,unsigned longtimeout);
146-
147-
voidshiftOut(uint8_tdataPin,uint8_tclockPin,uint8_tbitOrder,uint8_tval);
148-
uint8_tshiftIn(uint8_tdataPin,uint8_tclockPin,uint8_tbitOrder);
149-
150-
voidattachInterrupt(uint8_t,void (*)(void),intmode);
151-
voiddetachInterrupt(uint8_t);
152-
153-
voidsetup(void);
154-
voidloop(void);
155-
15668
// Get the bit location within the hardware port of the given virtual pin.
15769
// This comes from the pins_*.c file for the active board configuration.
15870

@@ -227,31 +139,14 @@ extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
227139
#endif
228140

229141
#ifdef__cplusplus
230-
#include"WCharacter.h"
231-
#include"WString.h"
232-
#include"HardwareSerial.h"
233-
#include"USBAPI.h"
142+
#include"UART.h"
143+
#include"USBCore.h"
144+
#include"CDC.h"
145+
#include"MSC.h"
234146
#if defined(HAVE_HWSERIAL0)&& defined(HAVE_CDCSERIAL)
235147
#error "Targets with both UART0 and CDC serial not supported"
236148
#endif
237149

238-
uint16_tmakeWord(uint16_tw);
239-
uint16_tmakeWord(byteh,bytel);
240-
241-
#defineword(...) makeWord(__VA_ARGS__)
242-
243-
unsigned longpulseIn(uint8_tpin,uint8_tstate,unsigned longtimeout=1000000L);
244-
unsigned longpulseInLong(uint8_tpin,uint8_tstate,unsigned longtimeout=1000000L);
245-
246-
voidtone(uint8_t_pin,unsignedintfrequency,unsigned longduration=0);
247-
voidnoTone(uint8_t_pin);
248-
249-
// WMath prototypes
250-
longrandom(long);
251-
longrandom(long,long);
252-
voidrandomSeed(unsigned long);
253-
longmap(long,long,long,long,long);
254-
255150
#endif
256151

257152
#include"pins_arduino.h"

‎cores/arduino/CDC.cpp‎

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
/* Copyright (c) 2011, Peter Barrett
42
**
53
** Permission to use, copy, modify, and/or distribute this software for
@@ -16,25 +14,31 @@
1614
** SOFTWARE.
1715
*/
1816

19-
#include"USBAPI.h"
17+
#defineRINGBUFFER_FORCE_SMALL_SIZE
18+
2019
#include<avr/wdt.h>
2120
#include<util/atomic.h>
21+
#include<avr/pgmspace.h>
22+
#include"CDC.h"
23+
#include"api/USBAPI.h"
24+
#include"USBCore.h"
25+
#include"api/Common.h"
2226

2327
#if defined(USBCON)
2428

2529
typedefstruct
2630
{
27-
u32dwDTERate;
28-
u8bCharFormat;
29-
u8 bParityType;
30-
u8 bDataBits;
31-
u8lineState;
31+
uint32_tdwDTERate;
32+
uint8_tbCharFormat;
33+
uint8_t bParityType;
34+
uint8_t bDataBits;
35+
uint8_tlineState;
3236
} LineInfo;
3337

3438
staticvolatile LineInfo _usbLineInfo = {57600,0x00,0x00,0x00,0x00 };
3539
staticvolatileint32_t breakValue = -1;
3640

37-
staticu8 wdtcsr_save;
41+
staticuint8_t wdtcsr_save;
3842

3943
#defineWEAK__attribute__ ((weak))
4044

@@ -62,16 +66,16 @@ bool isLUFAbootloader()
6266
returnpgm_read_word(FLASHEND -1) == NEW_LUFA_SIGNATURE;
6367
}
6468

65-
intCDC_GetInterface(u8* interfaceNum)
69+
intCDC_GetInterface(uint8_t* interfaceNum)
6670
{
6771
interfaceNum[0] +=2;// uses 2
6872
returnUSB_SendControl(TRANSFER_PGM,&_cdcInterface,sizeof(_cdcInterface));
6973
}
7074

7175
boolCDC_Setup(USBSetup& setup)
7276
{
73-
u8 r = setup.bRequest;
74-
u8 requestType = setup.bmRequestType;
77+
uint8_t r = setup.bRequest;
78+
uint8_t requestType = setup.bmRequestType;
7579

7680
if (REQUEST_DEVICETOHOST_CLASS_INTERFACE == requestType)
7781
{

‎cores/arduino/CDC.h‎

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#ifndef __CDC_H__
2+
#define__CDC_H__
3+
4+
#include"api/Stream.h"
5+
#include"api/USBAPI.h"
6+
7+
#if defined (USBCON)
8+
9+
//================================================================================
10+
//================================================================================
11+
//Serial over CDC (Serial1 is the physical port)
12+
13+
#defineRINGBUFFER_FORCE_SMALL_SIZE
14+
#include"api/RingBuffer.h"
15+
16+
#ifndef SERIAL_BUFFER_SIZE
17+
#if ((RAMEND - RAMSTART) < 1023)
18+
#defineSERIAL_BUFFER_SIZE16
19+
#else
20+
#defineSERIAL_BUFFER_SIZE64
21+
#endif
22+
#endif
23+
#if (SERIAL_BUFFER_SIZE > 256)
24+
#error Please lower the CDC Buffer size
25+
#endif
26+
27+
classSerial_ :publicStream
28+
{
29+
private:
30+
int peek_buffer;
31+
public:
32+
Serial_() { peek_buffer = -1; };
33+
voidbegin(unsignedlong);
34+
voidbegin(unsignedlong,uint8_t);
35+
voidend(void);
36+
37+
virtualintavailable(void);
38+
virtualintpeek(void);
39+
virtualintread(void);
40+
virtualintavailableForWrite(void);
41+
virtualvoidflush(void);
42+
virtualsize_twrite(uint8_t);
43+
virtualsize_twrite(constuint8_t*,size_t);
44+
using Print::write;// pull in write(str) and write(buf, size) from Print
45+
operatorbool();
46+
47+
//RingBuffer _rx_buffer(SERIAL_BUFFER_SIZE);
48+
49+
// This method allows processing "SEND_BREAK" requests sent by
50+
// the USB host. Those requests indicate that the host wants to
51+
// send a BREAK signal and are accompanied by a single uint16_t
52+
// value, specifying the duration of the break. The value 0
53+
// means to end any current break, while the value 0xffff means
54+
// to start an indefinite break.
55+
// readBreak() will return the value of the most recent break
56+
// request, but will return it at most once, returning -1 when
57+
// readBreak() is called again (until another break request is
58+
// received, which is again returned once).
59+
// This also mean that if two break requests are received
60+
// without readBreak() being called in between, the value of the
61+
// first request is lost.
62+
// Note that the value returned is a long, so it can return
63+
// 0-0xffff as well as -1.
64+
int32_treadBreak();
65+
66+
// These return the settings specified by the USB host for the
67+
// serial port. These aren't really used, but are offered here
68+
// in case a sketch wants to act on these settings.
69+
uint32_tbaud();
70+
uint8_tstopbits();
71+
uint8_tparitytype();
72+
uint8_tnumbits();
73+
booldtr();
74+
boolrts();
75+
enum {
76+
ONE_STOP_BIT =0,
77+
ONE_AND_HALF_STOP_BIT =1,
78+
TWO_STOP_BITS =2,
79+
};
80+
enum {
81+
NO_PARITY =0,
82+
ODD_PARITY =1,
83+
EVEN_PARITY =2,
84+
MARK_PARITY =3,
85+
SPACE_PARITY =4,
86+
};
87+
88+
};
89+
extern Serial_ Serial;
90+
91+
#defineHAVE_CDCSERIAL
92+
93+
//================================================================================
94+
//================================================================================
95+
//CSC 'Driver'
96+
97+
intCDC_GetInterface(uint8_t* interfaceNum);
98+
intCDC_GetDescriptor(int i);
99+
boolCDC_Setup(USBSetup& setup);
100+
101+
#endif
102+
103+
#endif

‎cores/arduino/Client.h‎

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp