Skip to content

Commit 7bfe1ff

Browse files
committed
started sduino development. pin definitions and wiring_digital ok.
1 parent 3baa549 commit 7bfe1ff

13 files changed

Lines changed: 2017 additions & 1 deletion

File tree

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ libboost-graph1.54.0 - generic graph components and algorithms in C++
5959
libboost-graph1.55-dev - generic graph components and algorithms in C++
6060
libboost-graph1.55.0 - generic graph components and algorithms in C++
6161

62+
Es fehlen selbst elementare peephole-Optimierungen:
63+
aufeinander folgende addw x,# und subw x,# werden nicht zusammengefasst
64+
Multiplikation mit zwei wird nicht durch bitshift ersetzt (besonders beim
65+
Arrayzugriff absurd)
66+
67+
68+
69+
70+
6271
## ST Standard Library
6372

6473
git clone https://github.com/g-gabber/STM8S_StdPeriph_Driver.git
@@ -330,4 +339,20 @@ SPI: 6,11,12,13 (gleiche Nummern, aber andere Reichenfolge -> fehlerträchtig)
330339
I2C: 7,8
331340
Seriell: 2,3
332341
Analog: 2,3,10,15,16
333-
342+
343+
344+
## Anmerkungen zur Arduino-Portierung
345+
346+
Die ganze Pin->Portadressen-Arithmetik könnte komlett entrümpelt werden. Statt
347+
Tabellen fest im Code enthalten.
348+
349+
digitalWrite wird spektakulär umständlich übersetzt. Hier lohnt sich
350+
Handassembler.
351+
352+
### Besondere Features, die von Arduino nicht unterstützt werden
353+
354+
Input-Capture-Mode: min. für Timer1 auf allen vier Kanälen möglich.
355+
356+
Encoder interface mode: Kann von Haus aus mit Quadratur-Encodern umgehen und
357+
in Hardware zählen -> perfekt für die Druckerschlitten-Motorsteuerung.
358+

STM8S_StdPeriph_Driver/inc/stm8s.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,13 @@ typedef uint16_t u16;
237237
typedef uint8_t u8;
238238

239239

240+
// SDCC defines a special Bool type, use that if available
241+
#ifdef __bool_true_false_are_defined
242+
#define TRUE true
243+
#define FALSE false
244+
#else
240245
typedef enum {FALSE = 0, TRUE = !FALSE} bool;
246+
#endif
241247

242248
typedef enum {RESET = 0, SET = !RESET} FlagStatus, ITStatus, BitStatus, BitAction;
243249

sdunio/Arduino.h

Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
1+
/*
2+
Arduino.h - Main include file for the Arduino SDK
3+
Copyright (c) 2005-2013 Arduino Team. All right reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
#ifndef Arduino_h
21+
#define Arduino_h
22+
23+
#include <stdlib.h>
24+
#include <stdbool.h>
25+
#include <string.h>
26+
#include <math.h>
27+
//#include <stdint.h>
28+
29+
//#include <avr/pgmspace.h>
30+
//#include <avr/io.h>
31+
//#include <avr/interrupt.h>
32+
#include <stm8s.h>
33+
34+
#include "binary.h"
35+
36+
// cancel out the PROGMEM attribute - used only for atmel CPUs
37+
#define PROGMEM
38+
39+
void yield(void);
40+
41+
#define HIGH 0x1
42+
#define LOW 0x0
43+
44+
#define INPUT 0x0
45+
#define OUTPUT 0x1
46+
#define INPUT_PULLUP 0x2
47+
48+
// undefine mathlib's pi if encountered
49+
#ifdef PI
50+
#undef PI
51+
#endif
52+
#ifdef HALF_PI
53+
#undef HALF_PI
54+
#endif
55+
#ifdef TWO_PI
56+
#undef TWO_PI
57+
#endif
58+
59+
#define PI 3.1415926535897932384626433832795
60+
#define HALF_PI 1.5707963267948966192313216916398
61+
#define TWO_PI 6.283185307179586476925286766559
62+
#define DEG_TO_RAD 0.017453292519943295769236907684886
63+
#define RAD_TO_DEG 57.295779513082320876798154814105
64+
#define EULER 2.718281828459045235360287471352
65+
66+
#define SERIAL 0x0
67+
#define DISPLAY 0x1
68+
69+
#define LSBFIRST 0
70+
#define MSBFIRST 1
71+
72+
#define CHANGE 1
73+
#define FALLING 2
74+
#define RISING 3
75+
76+
/*
77+
#if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
78+
#define DEFAULT 0
79+
#define EXTERNAL 1
80+
#define INTERNAL1V1 2
81+
#define INTERNAL INTERNAL1V1
82+
#elif defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
83+
#define DEFAULT 0
84+
#define EXTERNAL 4
85+
#define INTERNAL1V1 8
86+
#define INTERNAL INTERNAL1V1
87+
#define INTERNAL2V56 9
88+
#define INTERNAL2V56_EXTCAP 13
89+
#else
90+
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__)
91+
#define INTERNAL1V1 2
92+
#define INTERNAL2V56 3
93+
#else
94+
#define INTERNAL 3
95+
#endif
96+
#define DEFAULT 1
97+
#define EXTERNAL 0
98+
#endif
99+
*/
100+
101+
// undefine stdlib's abs if encountered
102+
#ifdef abs
103+
#undef abs
104+
#endif
105+
106+
#define min(a,b) ((a)<(b)?(a):(b))
107+
#define max(a,b) ((a)>(b)?(a):(b))
108+
#define abs(x) ((x)>0?(x):-(x))
109+
#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
110+
#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
111+
#define radians(deg) ((deg)*DEG_TO_RAD)
112+
#define degrees(rad) ((rad)*RAD_TO_DEG)
113+
#define sq(x) ((x)*(x))
114+
115+
#define interrupts() sei()
116+
#define noInterrupts() cli()
117+
118+
#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
119+
#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
120+
#define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() )
121+
122+
#define lowByte(w) ((uint8_t) ((w) & 0xff))
123+
#define highByte(w) ((uint8_t) ((w) >> 8))
124+
125+
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
126+
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
127+
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
128+
#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit))
129+
130+
// avr-libc defines _NOP() since 1.6.2
131+
#ifndef _NOP
132+
#define _NOP() do { __asm__ volatile ("nop"); } while (0)
133+
#endif
134+
135+
typedef unsigned int word;
136+
137+
#define bit(b) (1UL << (b))
138+
139+
typedef unsigned char boolean;
140+
typedef unsigned char byte;
141+
//typedef uint8_t byte;
142+
143+
void init(void);
144+
void initVariant(void);
145+
146+
//int atexit(void (*func)()) __attribute__((weak));
147+
148+
void pinMode(uint8_t pin, uint8_t mode);
149+
void digitalWrite(uint8_t pin, uint8_t val);
150+
int digitalRead(uint8_t pin);
151+
int analogRead(uint8_t pin);
152+
void analogReference(uint8_t mode);
153+
void analogWrite(uint8_t pin, int val);
154+
155+
unsigned long millis(void);
156+
unsigned long micros(void);
157+
void delay(unsigned long ms);
158+
void delayMicroseconds(unsigned int us);
159+
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
160+
unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout);
161+
162+
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val);
163+
uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder);
164+
165+
void attachInterrupt(uint8_t, void (*)(void), int mode);
166+
void detachInterrupt(uint8_t);
167+
168+
void setup(void);
169+
void loop(void);
170+
171+
// Get the bit location within the hardware port of the given virtual pin.
172+
// This comes from the pins_*.c file for the active board configuration.
173+
174+
#define analogInPinToBit(P) (P)
175+
176+
// On the ATmega1280, the addresses of some of the port registers are
177+
// greater than 255, so we can't store them in uint8_t's.
178+
extern const uint16_t port_to_mode_PGM[];
179+
extern const uint16_t PROGMEM port_to_input_PGM[];
180+
extern const uint16_t PROGMEM port_to_output_PGM[];
181+
182+
extern const uint8_t PROGMEM digital_pin_to_port_PGM[];
183+
// extern const uint8_t PROGMEM digital_pin_to_bit_PGM[];
184+
extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[];
185+
extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
186+
187+
// Get the bit location within the hardware port of the given virtual pin.
188+
// This comes from the pins_*.c file for the active board configuration.
189+
//
190+
#define digitalPinToPort(P) ( digital_pin_to_port_PGM[(P)] )
191+
#define digitalPinToBitMask(P) ( digital_pin_to_bit_mask_PGM[(P)] )
192+
#define digitalPinToTimer(P) ( digital_pin_to_timer_PGM[(P)] )
193+
#define analogInPinToBit(P) (P)
194+
#define portOutputRegister(P) ( (volatile uint8_t *)( port_to_output_PGM[(P)]) )
195+
#define portInputRegister(P) ( (volatile uint8_t *)( port_to_input_PGM[(P)]) )
196+
#define portModeRegister(P) ( (volatile uint8_t *)( port_to_mode_PGM[(P)]) )
197+
198+
#define NOT_A_PIN 0
199+
#define NOT_A_PORT 0
200+
201+
#define NOT_AN_INTERRUPT -1
202+
203+
#ifdef ARDUINO_MAIN
204+
#define PA 1
205+
#define PB 2
206+
#define PC 3
207+
#define PD 4
208+
#define PE 5
209+
#define PF 6
210+
#define PG 7
211+
#define PH 8
212+
#define PJ 10
213+
#define PK 11
214+
#define PL 12
215+
#endif
216+
217+
#define NOT_ON_TIMER 0
218+
#define TIMER11 1
219+
#define TIMER12 2
220+
#define TIMER13 3
221+
#define TIMER14 4
222+
#define TIMER21 5
223+
#define TIMER22 6
224+
#define TIMER23 7
225+
226+
227+
//FIXME#include "WCharacter.h"
228+
//FIXME#include "WString.h"
229+
//FIXME#include "HardwareSerial.h"
230+
231+
//uint16_t makeWord(uint16_t w);
232+
//uint16_t makeWord(byte h, byte l);
233+
234+
//#define word(...) makeWord(__VA_ARGS__)
235+
236+
unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout);
237+
unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout);
238+
239+
void tone(uint8_t _pin, unsigned int frequency, unsigned long duration);
240+
void noTone(uint8_t _pin);
241+
242+
// WMath prototypes
243+
/*FIXME
244+
long random(long);
245+
long random(long, long);
246+
void randomSeed(unsigned long);
247+
long map(long, long, long, long, long);
248+
*/
249+
250+
#include "pins_arduino.h"
251+
252+
#endif

sdunio/Makefile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
EXECUTABLE=alles.ihx
2+
3+
CC=/usr/bin/sdcc
4+
CFLAGS= -mstm8 -DF_CPU=16000000L -DSTM8S103 --no-peep \
5+
-I/usr/share/sdcc/include/ -I$(LIBBASE)/inc -I.
6+
7+
LIBBASE=../STM8S_StdPeriph_Driver
8+
LIBFILES=$(LIBBASE)/src/stm8s.lib
9+
LDFLAGS=-L../STM8S_StdPeriph_Driver/src -lstm8s
10+
11+
OBJECTS=wiring.rel wiring_digital.rel test.rel
12+
13+
.PHONY: all clean
14+
15+
#all: $(OBJECTS)
16+
17+
$(EXECUTABLE): $(OBJECTS)
18+
#test.rel wiring_digital.rel
19+
$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@
20+
21+
$(OBJECTS) : %.rel : %.c
22+
$(CC) -c $(CFLAGS) $^
23+
24+
.c.o:
25+
$(CC) -c $(CFLAGS) $^ -o $@
26+
27+
.c.rel:
28+
$(CC) -c $(CFLAGS) $^
29+
30+
clean:
31+
rm -f *.lib *.rst *.rel *.lst *.ihx *.sym *.asm *.lk *.map *.cdb \
32+
*~ *.bak
33+
rm -f $(EXECUTABLE)

0 commit comments

Comments
 (0)