From 2801fc4f061b7614ab4cb95c5420a8c1c0772212 Mon Sep 17 00:00:00 2001 From: olivier gillet Date: Thu, 21 Apr 2011 19:34:13 +0200 Subject: [PATCH 1/3] Strip _ from resource strings --- tools/resources_compiler.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/resources_compiler.py b/tools/resources_compiler.py index f2667d2..dbf7197 100755 --- a/tools/resources_compiler.py +++ b/tools/resources_compiler.py @@ -57,6 +57,8 @@ def Canonicalize(x): out_chr[i] = ord('x') elif chr(i) == '"': out_chr[i] = ord('p') + elif chr(i) == '|': + out_chr[i] = ord('v') else: out_chr[i] = ord('_') table = string.maketrans(in_chr, ''.join(map(chr, out_chr))) @@ -141,7 +143,7 @@ def GenerateCc(base_name, res): if python_type == str: for string in resource: args = (c_type, '%s_%s' % (prefix.lower(), Canonicalize(string)), - res.modifier, string.strip()) + res.modifier, string.strip().replace('_', ' ')) f.write('static const %s %s[] %s = "%s";\n' % args) if ram: args = (c_type, table_name) From aa1a2a8961ef659998659655cd2e04ef35f07c0f Mon Sep 17 00:00:00 2001 From: olivier gillet Date: Fri, 22 Apr 2011 15:09:16 +0200 Subject: [PATCH 2/3] Added support for parallel IO on 6-bits ports (PORTC on 328p and 168p) --- parallel_io.h | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/parallel_io.h b/parallel_io.h index 82e221b..f3e4165 100755 --- a/parallel_io.h +++ b/parallel_io.h @@ -29,7 +29,9 @@ namespace avrlib { enum ParallelPortMode { PARALLEL_BYTE, PARALLEL_NIBBLE_HIGH, - PARALLEL_NIBBLE_LOW + PARALLEL_NIBBLE_LOW, + PARALLEL_TRIPLE_HIGH, + PARALLEL_TRIPLE_LOW }; template @@ -56,6 +58,22 @@ struct ShiftMasks { }; }; +template<> +struct ShiftMasks { + enum Masks { + mask = 0x78, + shift = 3, + }; +}; + +template<> +struct ShiftMasks { + enum Masks { + mask = 0x07, + shift = 0, + }; +}; + template struct ParallelPort { typedef ShiftMasks Masks; From 78b6a8fceb50bf60f491e2f86708b9970406ea7d Mon Sep 17 00:00:00 2001 From: pichenettes Date: Sun, 24 Apr 2011 03:32:27 +0200 Subject: [PATCH 3/3] Added support for SPI slave mode --- gpio.h | 8 ++++---- spi.h | 50 ++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/gpio.h b/gpio.h index 877a2df..e064dfe 100755 --- a/gpio.h +++ b/gpio.h @@ -175,8 +175,8 @@ SetupGpio(22, PortC, NoPwmChannel, 6); SetupGpio(23, PortC, NoPwmChannel, 7); const uint8_t kSpiSlaveSelectPin = 4; -const uint8_t kSpiDataOutPin = 5; -const uint8_t kSpiDataInPin = 6; +const uint8_t kSpiMosiPin = 5; +const uint8_t kSpiMisoPin = 6; const uint8_t kSpiClockPin = 7; #else @@ -204,8 +204,8 @@ SetupGpio(18, PortC, NoPwmChannel, 4); SetupGpio(19, PortC, NoPwmChannel, 5); const uint8_t kSpiSlaveSelectPin = 10; -const uint8_t kSpiDataOutPin = 11; -const uint8_t kSpiDataInPin = 12; +const uint8_t kSpiMosiPin = 11; +const uint8_t kSpiMisoPin = 12; const uint8_t kSpiClockPin = 13; #endif // ATMEGA328P diff --git a/spi.h b/spi.h index 327af1b..09a2417 100644 --- a/spi.h +++ b/spi.h @@ -25,7 +25,6 @@ // around 15 cycles (not including the interrupt prelude/postlude), which is // close to the transmission time at the fastest speed. // - the atmega is always configured as a master. -// - no support for reading back from the slave. #ifndef AVRLIB_SPI_H_ #define AVRLIB_SPI_H_ @@ -42,7 +41,7 @@ typedef BitInRegister TransferComplete; template -class Spi { +class SPIMaster { public: enum { buffer_size = 0, @@ -105,11 +104,54 @@ class Spi { private: typedef Gpio SlaveSelect; typedef Gpio GlobalSlaveSelect; - typedef Gpio DataOut; - typedef Gpio DataIn; + typedef Gpio DataOut; + typedef Gpio DataIn; typedef Gpio Clock; }; +template +class SPISlave { + public: + enum { + buffer_size = 128, + data_size = 8 + }; + + static void Init() { + Clock::set_mode(DIGITAL_INPUT); + DataIn::set_mode(DIGITAL_INPUT); + DataOut::set_mode(DIGITAL_OUTPUT); + GlobalSlaveSelect::set_mode(DIGITAL_INPUT); // Ohhh mistress, ohhhh! + SlaveSelect::set_mode(DIGITAL_INPUT); + + // SPI enabled, configured as master. + uint8_t configuration = _BV(SPE); + if (order == LSB_FIRST) { + configuration |= _BV(DORD); + } + if (enable_interrupt) { + configuration |= _BV(SPIE); + } + SPCR = configuration; + } + + static inline uint8_t Read(uint8_t v) { + while (!TransferComplete::value()); + return SPDR; + } + + private: + typedef Gpio SlaveSelect; + typedef Gpio GlobalSlaveSelect; + typedef Gpio DataOut; + typedef Gpio DataIn; + typedef Gpio Clock; +}; + +#define SPI_RECEIVE ISR(SPI_STC_vect) + } // namespace avrlib #endif AVRLIB_SPI_H_