Permalink
Browse files

Adding support for boards based on ATmega1284P.

  • Loading branch information...
1 parent f02bf95 commit 568177b054478886f11a3bdcfed10f6b928a430d @mikaelpatel committed Feb 23, 2013
Showing with 203 additions and 4 deletions.
  1. +137 −0 Cosa/Board.hh
  2. +62 −1 Cosa/Pins.cpp
  3. +4 −3 Cosa/SPI/Driver/NRF24L01P.hh
View
@@ -172,6 +172,143 @@ public:
};
};
+#elif defined(__AVR_ATmega1284P__)
+
+class Board {
+ friend class Pin;
+ friend class UART;
+private:
+ /**
+ * Do not allow instances. This is a static singleton.
+ */
+ Board() {}
+
+ /**
+ * Return Special Function Register for given Arduino pin number.
+ * @param[in] pin number.
+ * @return special register pointer.
+ */
+ static volatile uint8_t* SFR(uint8_t pin)
+ {
+ return (pin < 8 ? &PINB :
+ pin < 14 ? &PIND :
+ pin < 24 ? &PINC :
+ &PINA);
+ }
+
+ /**
+ * Return bit position for given Arduino pin number in Special
+ * Function Register.
+ * @param[in] pin number.
+ * @return pin bit position.
+ */
+ static const uint8_t BIT(uint8_t pin)
+ {
+ return (pin & 0x7);
+ }
+
+ /**
+ * Return UART Register for given Arduino serial port.
+ * @param[in] port number.
+ * @return UART register pointer.
+ */
+ static volatile uint8_t* UART(uint8_t port)
+ {
+ return (&UCSR0A);
+ }
+
+public:
+ /**
+ * Digital pin symbols
+ */
+ enum DigitalPin {
+ D0 = 0,
+ D1,
+ D2,
+ D3,
+ D4,
+ D5,
+ D6,
+ D7,
+ D8,
+ D9,
+ D10,
+ D11,
+ D12,
+ D13,
+ D14,
+ D15,
+ D16,
+ D17,
+ D18,
+ D19,
+ D20,
+ D21,
+ D22,
+ D23,
+ LED = D13
+ };
+
+ /**
+ * Analog pin symbols
+ */
+ enum AnalogPin {
+ A0 = 24,
+ A1,
+ A2,
+ A3,
+ A4,
+ A5,
+ A6,
+ A7,
+ A8
+ };
+
+ /**
+ * PWM pin symbols; sub-set of digital pins to allow compile
+ * time checking
+ */
+ enum PWMPin {
+ PWM0 = D3,
+ PWM1 = D4,
+ PWM2 = D6,
+ PWM3 = D7,
+ PWM4 = D12,
+ PWM5 = D13,
+ PWM6 = D14,
+ PWM7 = D15
+ };
+
+ /**
+ * External interrupt pin symbols; sub-set of digital pins
+ * to allow compile time checking.
+ */
+ enum InterruptPin {
+ EXT0 = D10,
+ EXT1 = D11,
+ EXT2 = D2,
+ EXT_MAX = 3
+ };
+
+ /**
+ * Pins used for TWI interface (in port C, digital pin 16, 17).
+ */
+ enum TWIPin {
+ SDA = 1,
+ SCL = 0
+ };
+
+ /**
+ * Pins used for SPI interface (in port B, digital pins 4-7).
+ */
+ enum SPIPin {
+ SS = 4,
+ MOSI = 5,
+ MISO = 6,
+ SCK = 7
+ };
+};
+
#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#define USART_UDRE_vect USART0_UDRE_vect
View
@@ -65,7 +65,8 @@ Pin::println(IOStream& stream)
#if defined(__AVR_ATmega8__) \
|| defined(__AVR_ATmega168__) \
- || defined(__AVR_ATmega328P__)
+ || defined(__AVR_ATmega328P__) \
+ || defined(__AVR_ATmega1284P__)
InterruptPin::InterruptPin(Board::InterruptPin pin, Mode mode) :
InputPin((Board::DigitalPin) pin)
@@ -235,6 +236,66 @@ PWMPin::set(uint8_t duty)
}
}
+#elif defined(__AVR_ATmega1284P__)
+
+uint8_t
+PWMPin::get_duty()
+{
+ switch (m_pin) {
+ case Board::PWM0: return (OCR0A);
+ case Board::PWM1: return (OCR0B);
+ case Board::PWM2: return (OCR3A);
+ case Board::PWM3: return (OCR3B);
+ case Board::PWM4: return (OCR1B);
+ case Board::PWM5: return (OCR1A);
+ case Board::PWM6: return (OCR2B);
+ case Board::PWM7: return (OCR2A);
+ default:
+ return (is_set());
+ }
+}
+
+void
+PWMPin::set(uint8_t duty)
+{
+ switch (m_pin) {
+ case Board::PWM0:
+ bit_set(TCCR0A, COM0A1);
+ OCR0A = duty;
+ return;
+ case Board::PWM1:
+ bit_set(TCCR0B, COM0B1);
+ OCR0B = duty;
+ return;
+ case Board::PWM2:
+ bit_set(TCCR3A, COM3A1);
+ OCR3A = duty;
+ return;
+ case Board::PWM3:
+ bit_set(TCCR3B, COM3B1);
+ OCR3B = duty;
+ return;
+ case Board::PWM4:
+ bit_set(TCCR1B, COM1B1);
+ OCR1B = duty;
+ return;
+ case Board::PWM5:
+ bit_set(TCCR1A, COM1A1);
+ OCR1A = duty;
+ return;
+ case Board::PWM6:
+ bit_set(TCCR2B, COM2B1);
+ OCR2B = duty;
+ return;
+ case Board::PWM7:
+ bit_set(TCCR2A, COM2A1);
+ OCR2A = duty;
+ return;
+ default:
+ OutputPin::set(duty);
+ }
+}
+
#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
uint8_t
@@ -98,9 +98,10 @@ public:
* @param[in] ce chip enable activates pin number (default D9/D48).
* @param[in] irq interrupt pin number (default EXT0/EXT4).
*/
-#if defined(__AVR_ATmega8__) || \
- defined(__AVR_ATmega168__) || \
- defined(__AVR_ATmega328P__)
+#if defined(__AVR_ATmega8__) || \
+ defined(__AVR_ATmega168__) || \
+ defined(__AVR_ATmega328P__) || \
+ defined(__AVR_ATmega1284P__)
NRF24L01P(uint8_t channel = 64,
Board::DigitalPin csn = Board::D10,
Board::DigitalPin ce = Board::D9,

0 comments on commit 568177b

Please sign in to comment.