This repository has been archived by the owner on Sep 1, 2022. It is now read-only.
forked from wovo/hwlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Wouter van Ooijen
committed
Jan 23, 2017
0 parents
commit 2edaa00
Showing
61 changed files
with
8,277 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
############################################################################# | ||
# | ||
# dummy Makefile for bmptk hwcpp directory | ||
# | ||
# (c) Wouter van Ooijen (www.voti.nl) 2016 | ||
# | ||
# 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) | ||
# | ||
############################################################################# | ||
|
||
.PHONY: clean build run error | ||
|
||
clean: error | ||
build: error | ||
run: error | ||
|
||
MSG = You are trying to build in a library directory. | ||
MSG += Make one of the project source files your current editor file. | ||
|
||
error: | ||
$(error $(MSG) ) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// ========================================================================== | ||
// | ||
// File : hwlib-adc.hpp | ||
// Part of : hwlib library for V1OOPC and V1IPAS | ||
// Copyright : [email protected] 2016 | ||
// | ||
// 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) | ||
// | ||
// ========================================================================== | ||
/// @file | ||
|
||
#ifndef HWLIB_ADC_H | ||
#define HWLIB_ADC_H | ||
|
||
#include "hwlib-panic.hpp" | ||
|
||
namespace hwlib { | ||
|
||
/// A/D input interface | ||
// | ||
/// This class abstracts the interface to an ADC (Analog to Digital Converter). | ||
class adc { | ||
public: | ||
|
||
/// the number of bits in the result returned by get() | ||
const int adc_n_bits; | ||
|
||
/// the type of the result returned by get() | ||
typedef unsigned int adc_value_type; | ||
|
||
/// do an A/D conversion and return the result | ||
// | ||
/// This function performs an A/D conversion and returns the result. | ||
/// The lower n_bits of the result are the conversion result, | ||
/// the remaining higher bits are 0. | ||
virtual adc_value_type get() = 0; | ||
|
||
/// specify the number of bits | ||
adc( int n_bits ): adc_n_bits{ n_bits }{ | ||
if( n_bits > static_cast<int>( 8 * sizeof( adc_value_type ))){ | ||
// the number of bits won't fit in the return type of get() | ||
HWLIB_PANIC_WITH_LOCATION; | ||
} | ||
} | ||
|
||
}; | ||
|
||
}; // namespace hwlib | ||
|
||
#endif // HWLIB_ADC_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// ========================================================================== | ||
// | ||
// File : hwlib-all.hpp | ||
// Part of : hwlib library for V1OOPC and V1IPAS | ||
// Copyright : [email protected] 2016 | ||
// | ||
// 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) | ||
// | ||
// ========================================================================== | ||
|
||
#ifndef HWLIB_ALL_H | ||
#define HWLIB_ALL_H | ||
|
||
#include "hwlib-defines.hpp" | ||
#include "hwlib-pin.hpp" | ||
#include "hwlib-pin-dummies.hpp" | ||
#include "hwlib-port.hpp" | ||
#include "hwlib-adc.hpp" | ||
#include "hwlib-dac.hpp" | ||
#include "hwlib-console.hpp" | ||
#include "hwlib-graphics.hpp" | ||
#include "hwlib-wait.hpp" | ||
#include "hwlib-ostream.hpp" | ||
#include "hwlib-panic.hpp" | ||
#include "hwlib-i2c.hpp" | ||
#include "hwlib-pcf8574a.hpp" | ||
#include "hwlib-pcf8591.hpp" | ||
#include "hwlib-spi.hpp" | ||
#include "hwlib-hc595.hpp" | ||
#include "hwlib-hd44780.hpp" | ||
#include "hwlib-glcd-5510.hpp" | ||
#include "hwlib-glcd-oled.hpp" | ||
#include "hwlib-demo.hpp" | ||
|
||
#endif // HWLIB_ALL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
// ========================================================================== | ||
// | ||
// File : hwlib-console.hpp | ||
// Part of : hwlib library for V1OOPC and V1IPAS | ||
// Copyright : [email protected] 2016 | ||
// | ||
// 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) | ||
// | ||
// ========================================================================== | ||
/// @file | ||
|
||
#ifndef HWLIB_CONSOLE_H | ||
#define HWLIB_CONSOLE_H | ||
|
||
#include <hwlib-ostream.hpp> | ||
|
||
namespace hwlib { | ||
|
||
/// console interface | ||
// | ||
/// This class implements an interface to a character console. | ||
/// | ||
/// A console is a rectangular windows of (ASCII) characters. | ||
/// A console implements the ostream interface, but it doesn't scroll: | ||
/// while the cursor is outside the visible character area | ||
/// (beyond the end of the line, or beyond the number of lines) | ||
/// any character writes will be ignored. | ||
/// Some characters are treated special: | ||
/// - '\n' clears the rest of the line, and then | ||
/// moves to the first position of the next line | ||
/// - '\r' puts the cursor at the start of the current line | ||
/// - '\c' moves the cursor to the top-left position | ||
/// | ||
/// The x and y coordinates are 0-origin and count to the right and down. | ||
/// In other words, the top-left character position is (0,0), and the bottom | ||
/// right character position is (rows - 1, columns - 1). | ||
/// | ||
/// \image html console-positions.png | ||
/// | ||
class console : public ostream { | ||
protected: | ||
|
||
/// the actual writing of a character | ||
// | ||
/// When this function is called, the the current cursor is | ||
/// guaranteed to be within the console, and the character is | ||
/// not one of the special characters (\n, \r, \c) | ||
virtual void putc_implementation( char c ) = 0; | ||
|
||
/// change the write location to x, y | ||
// | ||
/// This function is called when the write location is | ||
/// changed *except* when it is changed to the next x | ||
/// position by a call to putc_implementation. | ||
/// | ||
/// The default implementation does nothing. | ||
virtual void goto_xy_implementation( int x, int y ){} | ||
|
||
|
||
public: | ||
|
||
/// the number of colums in the console | ||
const int columns; | ||
|
||
/// the number of lines (rows) in the console | ||
const int lines; | ||
|
||
/// the current write column; | ||
int x; | ||
|
||
/// the current write line; | ||
int y; | ||
|
||
/// construct a console from its columns (X size) and lines (Y size) | ||
console( | ||
int columns, | ||
int lines | ||
): | ||
columns{ columns }, | ||
lines{ lines } | ||
{} | ||
|
||
/// put the cursor (write location) at x, y | ||
virtual void goto_xy( int new_x, int new_y ){ | ||
x = new_x; | ||
y = new_y; | ||
} | ||
|
||
/// write a single character | ||
void putc( char c ) override { | ||
if( c == '\n' ){ | ||
goto_xy( 0, y + 1 ); | ||
|
||
} else if( c == '\r' ){ | ||
goto_xy( 0, y ); | ||
|
||
} else if( c == '\v' ){ | ||
goto_xy( 0, 0 ); | ||
|
||
} else if( | ||
( x >= 0 ) | ||
&& ( x < columns ) | ||
&& ( y >= 0 ) | ||
&& ( y < lines ) | ||
){ | ||
putc_implementation( c ); | ||
++x; | ||
} | ||
} | ||
|
||
/// clear the console | ||
// | ||
/// This function clears the console and puts the cursor at (0,0). | ||
/// The default implementation does this by writing spaces to all | ||
/// locations. A concrete implementation might provide | ||
/// a better (faster) way. | ||
virtual void clear(){ | ||
for( int y = 0; y < lines; ++y ){ | ||
goto_xy( 0, y ); | ||
for( int x = 0; x < columns; ++x ){ | ||
putc( ' ' ); | ||
} | ||
} | ||
goto_xy( 0, 0 ); | ||
} | ||
|
||
}; // class console | ||
|
||
}; // namespace hwlib | ||
|
||
#endif // HWLIB_CONSOLE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// ========================================================================== | ||
// | ||
// File : hwlib-dac.hpp | ||
// Part of : hwlib library for V1OOPC and V1IPAS | ||
// Copyright : [email protected] 2016 | ||
// | ||
// 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) | ||
// | ||
// ========================================================================== | ||
/// @file | ||
|
||
#ifndef HWLIB_DAC_H | ||
#define HWLIB_DAC_H | ||
|
||
#include "hwlib-panic.hpp" | ||
|
||
namespace hwlib { | ||
|
||
/// D/A output interface | ||
// | ||
/// This class abstracts the interface to a DAC (Digital to Analog Converter). | ||
class dac { | ||
public: | ||
|
||
/// the number of bits in the result returned by get() | ||
const int dac_n_bits; | ||
|
||
/// the type of the result returned by get() | ||
typedef unsigned int dac_value_type; | ||
|
||
/// write a value to the D/A output | ||
// | ||
/// This writes a digital value to the D/A converter, which causes | ||
/// the corresponding analog value to appear on the output pin. | ||
virtual void set( dac_value_type x ) = 0; | ||
|
||
/// specify the number of bits | ||
dac( int n_bits ): dac_n_bits{ n_bits }{ | ||
if( dac_n_bits > static_cast<int>( 8 * sizeof( dac_value_type ))){ | ||
// the number of bits won't fit in the return type of get() | ||
HWLIB_PANIC_WITH_LOCATION; | ||
} | ||
} | ||
|
||
}; | ||
|
||
}; // namespace hwlib | ||
|
||
#endif // HWLIB_DAC_H |
Oops, something went wrong.