Open GoogleCodeExporter opened 9 years ago
I prefer const int xxx = 0 over #defines.
I need this kind of pin naming abstraction to do a good job on a complete OSC
library for Arduino.
Original comment by newsfr...@gmail.com
on 26 Aug 2009 at 4:18
Looking over this header file, it seems to have both too much information (e.g.
the pin number to port/bit
mappings which are already in the pins_arduino files - albeit in a less useful
form) and too little (e.g. register
and bit names). What do you think about starting with the existing Arduino
libraries? That is, refactoring them
so they work on multiple processors, and then checking which constants are
needed to do so?
Original comment by dmel...@gmail.com
on 6 Sep 2009 at 7:35
Here is a specific usage case for the Ethernet library.
Index: utility/spi.h
===================================================================
--- utility/spi.h (revision 784)
+++ utility/spi.h (working copy)
@@ -9,23 +9,6 @@
#define BIT6 0x40
#define BIT7 0x80
-#define SPI0_SS_BIT BIT2
-#define SPI0_SS_DDR DDRB
-#define SPI0_SS_PORT PORTB
-
-#define SPI0_SCLK_BIT BIT5
-#define SPI0_SCLK_DDR DDRB
-#define SPI0_SCLK_PORT PORTB
-
-#define SPI0_MOSI_BIT BIT3
-#define SPI0_MOSI_DDR DDRB
-#define SPI0_MOSI_PORT PORTB
-
-#define SPI0_MISO_BIT BIT4
-#define SPI0_MISO_DDR DDRB
-#define SPI0_MISO_PORT PORTB
-
-
#define SPI0_WaitForReceive()
#define SPI0_RxData() (SPDR)
@@ -36,9 +19,14 @@
#define SPI0_RecvBute() SPI0_RxData()
// PB4(MISO), PB3(MOSI), PB5(SCK), PB2(/SS) // CS=1, waiting for SPI start
// SPI mode 0, 4MHz
-#define SPI0_Init() DDRB |= SPI0_SS_BIT|SPI0_SCLK_BIT|SPI0_MOSI_BIT;\
- PORTB |= SPI0_SS_BIT; PORTB &= ~(SPI0_SCLK_BIT|SPI0_MOSI_BIT);\
- SPCR = 0x50
+#define SPI0_Init() pinMode(CORE_SS0_PIN, OUTPUT); \
+ pinMode(CORE_SCLK_PIN, OUTPUT); \
+ pinMode(CORE_MOSI_PIN, OUTPUT); \
+ digitalWrite(CORE_SS0_PIN, HIGH); \
+ digitalWrite(CORE_SCLK_PIN, LOW); \
+ digitalWrite(CORE_MOSI_PIN, LOW); \
+ SPCR = 0x50
+
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
@@ -47,12 +35,7 @@
#define IINCHIP_SpiSendData SPI0_SendByte
#define IINCHIP_SpiRecvData SPI0_RxData
-
-#define IINCHIP_CS_BIT BIT2
-#define IINCHIP_CS_DDR DDRB
-#define IINCHIP_CS_PORT PORTB
-
-#define IINCHIP_CSInit() (IINCHIP_CS_DDR |= IINCHIP_CS_BIT)
-#define IINCHIP_CSon() (IINCHIP_CS_PORT |= IINCHIP_CS_BIT)
-#define IINCHIP_CSoff() (IINCHIP_CS_PORT &= ~IINCHIP_CS_BIT)
+#define IINCHIP_CSInit() pinMode(CORE_SS0_PIN, OUTPUT)
+#define IINCHIP_CSon() CORE_PORTREG(CORE_SS0_PIN) |=
CORE_BITMASK(CORE_SS0_PIN)
+#define IINCHIP_CSoff() CORE_PORTREG(CORE_SS0_PIN) &=
~CORE_BITMASK(CORE_SS0_PIN)
//-----------------------------------------------------------------------------
Original comment by paul.sto...@gmail.com
on 5 Nov 2009 at 7:31
Attachments:
This header has all the redundant register definitions removed. These will not
be
needed when digitialWrite() can compile to a single instruction when the input
is a
compile time constant.
Original comment by paul.sto...@gmail.com
on 7 Nov 2009 at 3:24
Attachments:
Initial implementation of macros to optimize digitalWrite() when both inputs are
compile-time constants.
Original comment by paul.sto...@gmail.com
on 13 Nov 2009 at 1:53
Attachments:
Updated spi.h for Ethernet, using these symbols. No #ifdef checks. All pin
manipulation is by pinMode() and digitalWrite(). Written for issue #203.
#include "wiring.h"
//-----------------------------------------------------------------------------
//AVR SPI HAL
#define SPI0_WaitForReceive()
#define SPI0_RxData() (SPDR)
#define SPI0_TxData(Data) (SPDR = Data)
#define SPI0_WaitForSend() while( (SPSR & 0x80)==0x00 )
#define SPI0_SendByte(Data) SPI0_TxData(Data);SPI0_WaitForSend()
#define SPI0_RecvBute() SPI0_RxData()
#define SPI0_Init() pinMode(CORE_SS0_PIN, OUTPUT); \
pinMode(CORE_SCLK0_PIN, OUTPUT); \
pinMode(CORE_MOSI0_PIN, OUTPUT); \
digitalWrite(CORE_SS0_PIN, HIGH); \
digitalWrite(CORE_SCLK0_PIN, LOW); \
digitalWrite(CORE_MOSI0_PIN, LOW); \
SPCR = 0x50
//-----------------------------------------------------------------------------
//IInChip SPI HAL
#define IINCHIP_SpiInit SPI0_Init
#define IINCHIP_SpiSendData SPI0_SendByte
#define IINCHIP_SpiRecvData SPI0_RxData
#define IINCHIP_CSInit() pinMode(CORE_SS0_PIN, OUTPUT)
#define IINCHIP_CSon() digitalWrite(CORE_SS0_PIN, HIGH)
#define IINCHIP_CSoff() digitalWrite(CORE_SS0_PIN, LOW)
//-----------------------------------------------------------------------------
Original comment by paul.sto...@gmail.com
on 11 Mar 2010 at 3:26
Attachments:
The ethernet and SD libraries still contain their own pin mapping details
rather than using pins_arduino.h. What needs to be done so that all the pin
mapping information is held in pins_arduino.h, and no processor or board
specific assumptions are made by the main libraries? Then 3rd party hardware
(my own included) can be supported without requiring changes to the standard
library functions.
Original comment by stevemar...@googlemail.com
on 20 Nov 2011 at 10:13
Original issue reported on code.google.com by
paul.sto...@gmail.com
on 19 Jul 2009 at 7:52Attachments: