Advertisement
Guest User

Untitled

a guest
Jun 18th, 2011
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.39 KB | None | 0 0
  1. # 1 "/home/oliver/AVR/io/test.cc"
  2. # 1 "<built-in>"
  3. # 1 "<command-line>"
  4. # 1 "/home/oliver/AVR/io/test.cc"
  5.  
  6. # 1 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/inttypes.h" 1 3
  7. # 37 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/inttypes.h" 3
  8. # 1 "/usr/local/avr/lib/gcc/avr/4.7.0/include/stdint.h" 1 3 4
  9.  
  10.  
  11. # 1 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h" 1 3 4
  12. # 121 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h" 3 4
  13. typedef int int8_t __attribute__((__mode__(__QI__)));
  14. typedef unsigned int uint8_t __attribute__((__mode__(__QI__)));
  15. typedef int int16_t __attribute__ ((__mode__ (__HI__)));
  16. typedef unsigned int uint16_t __attribute__ ((__mode__ (__HI__)));
  17. typedef int int32_t __attribute__ ((__mode__ (__SI__)));
  18. typedef unsigned int uint32_t __attribute__ ((__mode__ (__SI__)));
  19.  
  20. typedef int int64_t __attribute__((__mode__(__DI__)));
  21. typedef unsigned int uint64_t __attribute__((__mode__(__DI__)));
  22. # 142 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h" 3 4
  23. typedef int16_t intptr_t;
  24.  
  25.  
  26.  
  27.  
  28. typedef uint16_t uintptr_t;
  29. # 159 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h" 3 4
  30. typedef int8_t int_least8_t;
  31.  
  32.  
  33.  
  34.  
  35. typedef uint8_t uint_least8_t;
  36.  
  37.  
  38.  
  39.  
  40. typedef int16_t int_least16_t;
  41.  
  42.  
  43.  
  44.  
  45. typedef uint16_t uint_least16_t;
  46.  
  47.  
  48.  
  49.  
  50. typedef int32_t int_least32_t;
  51.  
  52.  
  53.  
  54.  
  55. typedef uint32_t uint_least32_t;
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63. typedef int64_t int_least64_t;
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. typedef uint64_t uint_least64_t;
  71. # 213 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h" 3 4
  72. typedef int8_t int_fast8_t;
  73.  
  74.  
  75.  
  76.  
  77. typedef uint8_t uint_fast8_t;
  78.  
  79.  
  80.  
  81.  
  82. typedef int16_t int_fast16_t;
  83.  
  84.  
  85.  
  86.  
  87. typedef uint16_t uint_fast16_t;
  88.  
  89.  
  90.  
  91.  
  92. typedef int32_t int_fast32_t;
  93.  
  94.  
  95.  
  96.  
  97. typedef uint32_t uint_fast32_t;
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105. typedef int64_t int_fast64_t;
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112. typedef uint64_t uint_fast64_t;
  113. # 273 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/stdint.h" 3 4
  114. typedef int64_t intmax_t;
  115.  
  116.  
  117.  
  118.  
  119. typedef uint64_t uintmax_t;
  120. # 4 "/usr/local/avr/lib/gcc/avr/4.7.0/include/stdint.h" 2 3 4
  121. # 38 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/inttypes.h" 2 3
  122. # 77 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/inttypes.h" 3
  123. typedef int32_t int_farptr_t;
  124.  
  125.  
  126.  
  127. typedef uint32_t uint_farptr_t;
  128. # 3 "/home/oliver/AVR/io/test.cc" 2
  129. # 1 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/io.h" 1 3
  130. # 99 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/io.h" 3
  131. # 1 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/sfr_defs.h" 1 3
  132. # 100 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/io.h" 2 3
  133. # 274 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/io.h" 3
  134. # 1 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/iom8.h" 1 3
  135. # 275 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/io.h" 2 3
  136. # 432 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/io.h" 3
  137. # 1 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/portpins.h" 1 3
  138. # 433 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/io.h" 2 3
  139.  
  140. # 1 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/common.h" 1 3
  141. # 435 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/io.h" 2 3
  142.  
  143. # 1 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/version.h" 1 3
  144. # 437 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/io.h" 2 3
  145.  
  146.  
  147. # 1 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/fuse.h" 1 3
  148. # 248 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/fuse.h" 3
  149. typedef struct
  150. {
  151.     unsigned char low;
  152.     unsigned char high;
  153. } __fuse_t;
  154. # 440 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/io.h" 2 3
  155.  
  156.  
  157. # 1 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/lock.h" 1 3
  158. # 443 "/usr/local/avr/lib/gcc/avr/4.7.0/../../../../avr/include/avr/io.h" 2 3
  159. # 4 "/home/oliver/AVR/io/test.cc" 2
  160.  
  161. class Port {
  162. public:
  163.     Port(volatile uint8_t* const ddr_address,
  164.          volatile uint8_t* const port_address);
  165.  
  166.     bool get_pin(uint8_t pin_number) const;
  167.     void set_pin(uint8_t pin_number) const;
  168. private:
  169.     volatile uint8_t* const ddr_address_;
  170.     volatile uint8_t* const port_address_;
  171. };
  172.  
  173. inline Port::Port(volatile uint8_t* const ddr_address,
  174.                   volatile uint8_t* const port_address)
  175. : ddr_address_(ddr_address),
  176.   port_address_(port_address)
  177. {
  178.  
  179.     return;
  180. }
  181.  
  182. inline bool Port::get_pin(uint8_t pin_number) const
  183. {
  184.     bool result = *port_address_ & (1 << pin_number);
  185.  
  186.     return result;
  187. }
  188.  
  189. inline void Port::set_pin(uint8_t pin_number) const
  190. {
  191.     *port_address_ |= (1 << pin_number);
  192.  
  193.     return;
  194. }
  195.  
  196. class Button
  197. {
  198. public:
  199.     Button(Port* port, const uint8_t pin_number, bool active_high);
  200.  
  201.     bool is_active() const;
  202.     bool has_changed() const;
  203.     bool activated() const;
  204.     bool deactivated() const;
  205.     void Poll();
  206.  
  207. private:
  208.     const Port* const port_;
  209.     const uint8_t pin_number_;
  210.     const bool active_high_;
  211.  
  212.     bool active_;
  213.     bool has_changed_;
  214. };
  215.  
  216.  
  217. inline Button::Button(Port* port, uint8_t pin_number, bool active_high)
  218. : port_(port),
  219.   pin_number_(pin_number),
  220.   active_high_(active_high),
  221.   active_(false),
  222.   has_changed_(false)
  223. {
  224.  
  225.     return;
  226. }
  227.  
  228. inline bool Button::is_active() const
  229. {
  230.     return active_;
  231. }
  232.  
  233. inline bool Button::has_changed() const
  234. {
  235.     return has_changed_;
  236. }
  237.  
  238. inline bool Button::activated() const
  239. {
  240.     bool activated = (is_active() && has_changed());
  241.  
  242.     return activated;
  243. }
  244.  
  245. inline bool Button::deactivated() const
  246. {
  247.     bool deactivated = ((!is_active()) && has_changed());
  248.  
  249.     return deactivated;
  250. }
  251.  
  252. inline void Button::Poll()
  253. {
  254.     bool new_state = (port_->get_pin(3) == active_high_);
  255.  
  256.     has_changed_ = (new_state != active_);
  257.  
  258.     active_ = new_state;
  259.  
  260.     return;
  261. }
  262.  
  263.  
  264. int main(void)
  265. {
  266.     const uint8_t pin = 3;
  267.     Port PortB = Port(&(*(volatile uint8_t *)((0x18) + 0x20)), &(*(volatile uint8_t *)((0x17) + 0x20)));
  268.     Button ButtonB2 = Button(&PortB, pin, true);
  269.  
  270.     ButtonB2.Poll();
  271.     bool active = ButtonB2.is_active();
  272.     bool has_changed = ButtonB2.has_changed();
  273.     bool activated = ButtonB2.activated();
  274.     bool deactivated = ButtonB2.deactivated();
  275.  
  276.     bool x = (active && has_changed && activated);
  277.  
  278.     if (x) PortB.set_pin(2);
  279.  
  280.     while (true) { }
  281.  
  282.     return 0;
  283. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement