Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 1 "/home/oliver/AVR/io/test.cc"
- # 1 "<built-in>"
- # 1 "<command-line>"
- # 1 "/home/oliver/AVR/io/test.cc"
- # 1 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/inttypes.h" 1 3
- # 37 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/inttypes.h" 3
- # 1 "/usr/local/avr/lib/gcc/avr/4.7.0/include/stdint.h" 1 3 4
- # 1 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h" 1 3 4
- # 121 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h" 3 4
- typedef int int8_t __attribute__((__mode__(__QI__)));
- typedef unsigned int uint8_t __attribute__((__mode__(__QI__)));
- typedef int int16_t __attribute__ ((__mode__ (__HI__)));
- typedef unsigned int uint16_t __attribute__ ((__mode__ (__HI__)));
- typedef int int32_t __attribute__ ((__mode__ (__SI__)));
- typedef unsigned int uint32_t __attribute__ ((__mode__ (__SI__)));
- typedef int int64_t __attribute__((__mode__(__DI__)));
- typedef unsigned int uint64_t __attribute__((__mode__(__DI__)));
- # 142 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h" 3 4
- typedef int16_t intptr_t;
- typedef uint16_t uintptr_t;
- # 159 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h" 3 4
- typedef int8_t int_least8_t;
- typedef uint8_t uint_least8_t;
- typedef int16_t int_least16_t;
- typedef uint16_t uint_least16_t;
- typedef int32_t int_least32_t;
- typedef uint32_t uint_least32_t;
- typedef int64_t int_least64_t;
- typedef uint64_t uint_least64_t;
- # 213 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h" 3 4
- typedef int8_t int_fast8_t;
- typedef uint8_t uint_fast8_t;
- typedef int16_t int_fast16_t;
- typedef uint16_t uint_fast16_t;
- typedef int32_t int_fast32_t;
- typedef uint32_t uint_fast32_t;
- typedef int64_t int_fast64_t;
- typedef uint64_t uint_fast64_t;
- # 273 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h" 3 4
- typedef int64_t intmax_t;
- typedef uint64_t uintmax_t;
- # 4 "/usr/local/avr/lib/gcc/avr/4.7.0/include/stdint.h" 2 3 4
- # 38 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/inttypes.h" 2 3
- # 77 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/inttypes.h" 3
- typedef int32_t int_farptr_t;
- typedef uint32_t uint_farptr_t;
- # 3 "/home/oliver/AVR/io/test.cc" 2
- # 1 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/io.h" 1 3
- # 99 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/io.h" 3
- # 1 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/sfr_defs.h" 1 3
- # 100 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/io.h" 2 3
- # 274 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/io.h" 3
- # 1 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/iom8.h" 1 3
- # 275 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/io.h" 2 3
- # 432 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/io.h" 3
- # 1 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/portpins.h" 1 3
- # 433 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/io.h" 2 3
- # 1 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/common.h" 1 3
- # 435 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/io.h" 2 3
- # 1 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/version.h" 1 3
- # 437 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/io.h" 2 3
- # 1 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/fuse.h" 1 3
- # 248 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/fuse.h" 3
- typedef struct
- {
- unsigned char low;
- unsigned char high;
- } __fuse_t;
- # 440 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/io.h" 2 3
- # 1 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/lock.h" 1 3
- # 443 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/io.h" 2 3
- # 4 "/home/oliver/AVR/io/test.cc" 2
- class Port {
- public:
- Port(volatile uint8_t* const ddr_address,
- volatile uint8_t* const port_address);
- bool get_pin(uint8_t pin_number) const;
- void set_pin(uint8_t pin_number) const;
- private:
- volatile uint8_t* const ddr_address_;
- volatile uint8_t* const port_address_;
- };
- inline Port::Port(volatile uint8_t* const ddr_address,
- volatile uint8_t* const port_address)
- : ddr_address_(ddr_address),
- port_address_(port_address)
- {
- return;
- }
- inline bool Port::get_pin(uint8_t pin_number) const
- {
- bool result = *port_address_ & (1 << pin_number);
- return result;
- }
- inline void Port::set_pin(uint8_t pin_number) const
- {
- *port_address_ |= (1 << pin_number);
- return;
- }
- class Button
- {
- public:
- Button(Port* port, const uint8_t pin_number, bool active_high);
- bool is_active() const;
- bool has_changed() const;
- bool activated() const;
- bool deactivated() const;
- void Poll();
- private:
- const Port* const port_;
- const uint8_t pin_number_;
- const bool active_high_;
- bool active_;
- bool has_changed_;
- };
- inline Button::Button(Port* port, uint8_t pin_number, bool active_high)
- : port_(port),
- pin_number_(pin_number),
- active_high_(active_high),
- active_(false),
- has_changed_(false)
- {
- return;
- }
- inline bool Button::is_active() const
- {
- return active_;
- }
- inline bool Button::has_changed() const
- {
- return has_changed_;
- }
- inline bool Button::activated() const
- {
- bool activated = (is_active() && has_changed());
- return activated;
- }
- inline bool Button::deactivated() const
- {
- bool deactivated = ((!is_active()) && has_changed());
- return deactivated;
- }
- inline void Button::Poll()
- {
- bool new_state = (port_->get_pin(3) == active_high_);
- has_changed_ = (new_state != active_);
- active_ = new_state;
- return;
- }
- int main(void)
- {
- const uint8_t pin = 3;
- Port PortB = Port(&(*(volatile uint8_t *)((0x18) + 0x20)), &(*(volatile uint8_t *)((0x17) + 0x20)));
- Button ButtonB2 = Button(&PortB, pin, true);
- ButtonB2.Poll();
- bool active = ButtonB2.is_active();
- bool has_changed = ButtonB2.has_changed();
- bool activated = ButtonB2.activated();
- bool deactivated = ButtonB2.deactivated();
- bool x = (active && has_changed && activated);
- if (x) PortB.set_pin(2);
- while (true) { }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement