Bare Metal Programming Tool Kit
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
demos.h
Go to the documentation of this file.
1 //***************************************************************************
2 //
3 // file : bmptk/hardware/demos.h
4 //
5 // LICENSE (MIT expat license, copy of bmptk/license.txt)
6 //
7 // Copyright (c) 2013 Wouter van Ooijen (wouter@voti.nl)
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE..
27 //
28 //***************************************************************************
29 
30 // document everything in this file
33 namespace bmptk {
34 namespace hardware {
35 
37 template< typename arg_pin, int flavour = arg_pin::type >
38 void blink( time t = 200 * bmptk::ms ){
39 
40  static_assert(
41  ( flavour == bmptk::type_pin_out )
42  | ( flavour == bmptk::type_pin_in_out )
43  | ( flavour == bmptk::type_pin_oc ),
44  "blink requires a pin_out, pin_in_out or a pin_oc"
45  );
46 
48  typedef bmptk::hardware::flipable< pin >flipper;
49 
50  pin::init();
51  for(;;){
52  bmptk::wait( t );
53  flipper::flip();
54  }
55 }
56 
58 template< typename arg_pin, int flavour = arg_pin::type >
59 void beep(
60  unsigned long long int period = 1 * bmptk::ms,
61  unsigned long long int duration = 500 * bmptk::ms
62 ){
63 
64  static_assert(
65  ( flavour == bmptk::type_pin_out )
66  | ( flavour == bmptk::type_pin_in_out )
67  | ( flavour == bmptk::type_pin_oc ),
68  "beep requires a pin_out, pin_in_out or a pin_oc"
69  );
70 
72 
73  pin::init();
74  while( duration > period ){
75  duration -= period;
76  pin::set( 1 );
77  bmptk::wait( duration / 2 );
78  pin::set( 0 );
79  bmptk::wait( duration / 2 );
80  }
81 }
82 
85 template< typename arg_port, int flavour = arg_port::type >
86 void kitt( bmptk::time t = 200 * bmptk::ms ){
87 
88  static_assert(
89  ( flavour == bmptk::type_port_out )
90  | ( flavour == bmptk::type_port_in_out )
91  | ( flavour == bmptk::type_port_oc ),
92  "kitt requires a port_out, port_in_out or a port_oc"
93  );
94 
96 
97  port::init();
98  for(;;){
99 
100  // walk the light from the 0th pin to the highest
101  for( int i = 0; i < port::n_pins(); i++ ){
102  port::set( 0x01 << i );
103  bmptk::wait( t );
104  }
105 
106  // walk the light back from the highest-minuus-1 to the 1st
107  for( int i = port::n_pins() - 2; i > 0; i-- ){
108  port::set( 0x01 << i );
109  bmptk::wait( t );
110  }
111  }
112 }
114 
115 }; // namespace hardware
116 }; // namespace bmptk;