Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
wovo committed Mar 13, 2019
1 parent bc51231 commit b2ef53f
Show file tree
Hide file tree
Showing 21 changed files with 372 additions and 97 deletions.
45 changes: 45 additions & 0 deletions attic/due-#010 - blink direct muti-target/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// ==========================================================================
//
// blink the LED on an Arduino Due
//
// (c) Wouter van Ooijen (wouter@voti.nl) 2017
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// ==========================================================================

#include "hwlib.hpp"

int main( void ){

if constexpr ( hwlib::target_board == hwlib::target_boards::arduino_uno ){

DDRB |= ( 0b01 << 5 );
for(;;){
PORTB &= ~( 0b01 << 5 );
for( volatile uint32_t i = 0; i < 50'000; ++i );
PORTB |= ( 0b01 << 5 );
for( volatile uint32_t i = 0; i < 50'000; ++i );
}

} else if constexpr ( hwlib::target_board == hwlib::target_boards::arduino_due ){

PIOB->PIO_OER = 0x01 << 27;
for(;;){
PIOB->PIO_SODR = 0x01 << 27;
for( volatile int i = 0; i < 100'000; i++ ){}
IOB->PIO_CODR = 0x01 << 27;
for( volatile int i = 0; i < 100'000; i++ ){}
}

} else {

void no_blink_variation_for_this_target();
no_blink_variation_for_this_target();

}

}

25 changes: 25 additions & 0 deletions attic/due-#010 - blink direct muti-target/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#============================================================================
#
# simple project makefile (just a main file)
#
# (c) Wouter van Ooijen (wouter@voti.nl) 2017
#
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#
#============================================================================

# source files in this project (main.* is automatically assumed)
SOURCES :=

# header files in this project
HEADERS :=

# other places to look for files for this project
SEARCH :=

# set RELATIVE to the next higher directory
# and defer to the appropriate Makefile.* there
RELATIVE := ..
include $(RELATIVE)/makefile.link
36 changes: 36 additions & 0 deletions demo/arduino-due/due-#089 - constexpr/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "hwlib.hpp"

namespace target = hwlib::target;

constexpr double pow( double v, int n ){
return ( n == 0 )
? 1
: v * pow( v, n - 1 );
}

constexpr int fac( int n ){
return ( n == 0 )
? 1
: n * fac( n - 1 );
}

constexpr double sine( double angle ){
double value = 0;
for( int i = 1; i < 10; i += 2 ){
value += (( i % 4 ) == 1 ? 1 : -1 ) * pow( angle, i ) / fac( i );
}
return value;
}

constexpr double pi = 3.14;

constexpr int height = static_cast< int >( 1000 * sine( 2 * pi / 12 ));

int main( void ){

// wait for the terminal emulator to start up
hwlib::wait_ms( 1'000 );

hwlib::cout << "1000 * sin( 30 ) = " << height << "\n";

}
28 changes: 28 additions & 0 deletions demo/arduino-due/due-#089 - constexpr/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#============================================================================
#
# simple project makefile (just a main file)
#
# (c) Wouter van Ooijen (wouter@voti.nl) 2017
#
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#
#============================================================================

# source files in this project (main.* is automatically assumed)
SOURCES :=

# header files in this project
HEADERS :=

# other places to look for files for this project
SEARCH :=

# other things to build
RESULTS := main.lss main.lst

# set RELATIVE to the next higher directory
# and defer to the appropriate Makefile.* there
RELATIVE := ..
include $(RELATIVE)/makefile.link
17 changes: 0 additions & 17 deletions demo/arduino-uno/.codelite/__codelite.session

This file was deleted.

Binary file modified demo/arduino-uno/.codelite/__codelite.tags
Binary file not shown.
Binary file modified demo/arduino-uno/.codelite/refactoring.db
Binary file not shown.
4 changes: 2 additions & 2 deletions demo/arduino-uno/__codelite.workspace
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<Project Name="001 - two" ConfigName="Release"/>
</WorkspaceConfiguration>
</BuildMatrix>
<Project Name="010 - blink - direct" Path="010 - blink - direct/_codelite.project" Active="No"/>
<Project Name="010 - blink - direct" Path="010 - blink - direct/_codelite.project" Active="Yes"/>
<BuildMatrix>
<WorkspaceConfiguration Name="Release" Selected="yes">
<Project Name="010 - blink - direct" ConfigName="Release"/>
Expand Down Expand Up @@ -42,7 +42,7 @@
<Project Name="031 - uart - input" ConfigName="Release"/>
</WorkspaceConfiguration>
</BuildMatrix>
<Project Name="lcd - scrolling message" Path="lcd - scrolling message/_codelite.project" Active="Yes"/>
<Project Name="lcd - scrolling message" Path="lcd - scrolling message/_codelite.project" Active="No"/>
<BuildMatrix>
<WorkspaceConfiguration Name="Release" Selected="yes">
<Project Name="lcd - scrolling message" ConfigName="Release"/>
Expand Down
33 changes: 33 additions & 0 deletions library/core/hwlib-targets.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// ==========================================================================
//
// File : hwlib-targets.hpp
// Part of : C++ hwlib library for close-to-the-hardware OO programming
// Copyright : wouter@voti.nl 2017-2019
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// ==========================================================================

// included only via hwlib.hpp, hence no multiple-include guard is needed

// this file contains Doxygen lines
/// @file

namespace hwlib {

enum class target_boards {
none,
arduino_uno,
arduino_due,
blue_pill
};

enum class target_chips {
atmega328p,
atsam3x8e,
stm32f103c8
};

}; // namespace hwlib
1 change: 1 addition & 0 deletions library/hwlib-all.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <type_traits>

#include HWLIB_INCLUDE( core/hwlib-defines.hpp )
#include HWLIB_INCLUDE( core/hwlib-targets.hpp )
#include HWLIB_INCLUDE( core/hwlib-panic.hpp )
#include HWLIB_INCLUDE( core/hwlib-common.hpp )
#include HWLIB_INCLUDE( core/hwlib-wait.hpp )
Expand Down
2 changes: 1 addition & 1 deletion library/peripherals/hwlib-hc595.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class hc595 : public port_out {
return 8;
}

void write( uint_fast8_t x ) override {
void write( uint_fast16_t x ) override {
write_buffer = x;
}

Expand Down
4 changes: 2 additions & 2 deletions library/peripherals/hwlib-pcf8574.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ class pcf8574 : public port_oc {
return 8;
}

void write( uint_fast8_t x ) override {
void write( uint_fast16_t x ) override {
write_buffer = x;
dirty = true;
}

uint_fast8_t read() override {
uint_fast16_t read() override {
return read_buffer;
}

Expand Down
12 changes: 6 additions & 6 deletions library/ports/hwlib-port-direct.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ class port_direct_from_in_out_t : public port_in_out {
return slave.number_of_pins();
}

void write( uint_fast8_t v ) override {
void write( uint_fast16_t v ) override {
slave.write( v );
slave.flush();
}

uint_fast8_t read() override {
uint_fast16_t read() override {
slave.refresh();
return slave.read();
}
Expand Down Expand Up @@ -106,7 +106,7 @@ class port_direct_from_in_t : public port_in {
return slave.number_of_pins();
}

uint_fast8_t read() override {
uint_fast16_t read() override {
slave.refresh();
return slave.read();
}
Expand Down Expand Up @@ -145,7 +145,7 @@ class port_direct_from_out_t : public port_out {
return slave.number_of_pins();
}

void write( uint_fast8_t v ) override {
void write( uint_fast16_t v ) override {
slave.write( v );
slave.flush();
}
Expand Down Expand Up @@ -184,12 +184,12 @@ class port_direct_from_oc_t : public port_oc {
return slave.number_of_pins();
}

void write( uint_fast8_t v ) override {
void write( uint_fast16_t v ) override {
slave.write( v );
slave.flush();
}

uint_fast8_t read() override {
uint_fast16_t read() override {
slave.refresh();
return slave.read();
}
Expand Down
Loading

0 comments on commit b2ef53f

Please sign in to comment.