Details Table Of Contents:
- Brief Intro
- Useful Code!
- More than just a bunch of commonly-used code; 'commonCode' is a system
- Examples (if the Linux Kernel used commonCode)
- A Little History
- A List of 'commonThings'
- Starting a new project
- System Design/Flow (in project log)
- Status
- Project Log Table Of Contents
- Licensing
- mehPL (my "meh public license")
Brief Intro
(Every code-bearing project I've made available contains a _commonCode_localized/ directory! Find out, here, what it does, and help me develop it further! Also, look here for more info.)
Useful Code!
I think the name says it, 'commonCode' is a bunch of useful code. But it's more than that.
Similar to a 'library', I refer to each piece of commonCode as a 'commonThing'. CommonThings cover a broad-range of functionality: math functions, graphics, motion-control, I/O, peripheral drivers, protocols, etc.
(A listing of 'commonThings' follows the next explanation. Scroll down, then Please click "Read More")
What is 'commonCode' besides just a bunch of commonly-used code?
'commonCode' is a system, implementing:
- Example/test-code – most commonThings come with dedicated test-code
- Similar to 'hello-world' or 'blinky' (or the ol' AVR 'gcc-tests') getting-started projects
- Great place to start a new project, to learn how to implement a commonThing in your own project, or even get-started with a new architecture/MCU.
- Centralized 'commonThings'
- Make a bug-fix or improvement to one commonThing, and it will be applied to all projects using that commonThing (when they're recompiled).
- Configuration/Optimization-options and Abstraction
- What pin is your LED connected-to? Configure that in your project configuration, rather than modifying the commonThing. (Think about the centralized-bug-fixes, mentioned above. Now think about having five concurrent projects with different pinouts, fixing a bug in one, then having to modify four other files either with the bugfix or to copy the file with the bugfix four times and modify each with the pinout which you'd already had defined in the previous unbugfixed 'library.')
- Don't need certain functionality a commonThing provides? Mark that portion as "unused" and recover some program-space.
- Want to use that fancy commonThing on a different architecture? Many commonThings are completely architecture-independent. Many other once-AVR-specific pieces of code are being abstracted with no speed/program-space penalty. E.G. Your MCU doesn't use PB4/PORTB definitions? Override the default *inline* LED-On/Off functions with your own. Or replace the default LED-On/Off functions with functions containing printf's, and simulate that fading LED-thing in a console window on your desktop-PC.
- Distribution-system
- Handles dependencies/versions
- Can create a package of your project and all necessary commonCode: 'make localize'
- Can extract commonCode from a downloaded-project, placing it in your central commonCode directory: 'make delocalize'
- ...This bit is hard to explain, see the example below
I don't know exactly how to describe it, but it's a bit more like a distribution-system ala 'apt-get' for reusable project-code; handling dependencies, versions, etc. keeping it all centralized, and allowing for project-specific customization without modifying the centralized code. And all it requires is the standard toolchain (C, preprocessor, make, etc.).
Examples (if the Linux Kernel used commonCode):
Example 1: Say you were compiling two Linux Kernels, side-by-side... one for your desktop and one for your android phone. Normally you'd have two *HUGE* and nearly-identical source-trees containing all the code needed by both kernels, and both also containing code for all the drivers for a bunch of systems you've never even seen before.
If the Linux Kernel used something like 'commonCode', you'd have two folders containing little more than the specific configuration-files necessary for your two targets, and a third containing all the common stuff (and, optionally, wouldn't even need to have the code for unused systems/drivers).
Example 2: If you were working on two separate (but numerically-near) versions of the kernel (possibly testing whether your custom driver's code is backwards-compatible?), it's quite likely that the two kernels' source-trees would be largely identical. So why have two separate copies if you're not even working on that stuff? Instead, a shared source-tree could e.g. contain drivers/graphics/someModelGPU/ and under that folder could be 1.00/ and 1.02/...
This is what makes 'commonCode' what it is... I don't do kernel-development, but the 'commonCode' system works great for other types of projects as well...
For AVRs and other limited-memory systems, this bit's also quite handy: 'commonThings' have options that make it a bit like using lib-math without it already being precompiled... E.G. If the sin()/cos() functions aren't used in your project, then don't compile them! You don't use some of the more esoteric <stdio.h> functions? Then why the heck are we compiling them into our program-memory? Etc. Etc. Etc. Again, this is an example. As it stands, this system only works with commonThings, not lib-math or stdio.
A Little History:
commonCode is *NOT* exclusively for AVRs, and is being detached from 'em more and more every-day. (see: #operation: Learn The MIPS (PIC32MX1xx/2xx), wherein commonCode is being abstracted and ported to PIC32)
I've been developing software for AVRs since before Arduino existed and have done literally dozens of projects, many in permanent installations, and many others are being constantly improved...
In the process I've written and reused a bunch of code a bunch of times...
And in *that* process, I've developed this method for keeping this oft-reused code in a central location, handling dependencies, versions, etc.
As I've been developing more with desktop-applications, I too have been modifying the commonCode system to be architecture-independent.
I've found that this system lends itself well to development of new projects...
I'll describe that after the list.
A List of 'commonThings'
The list below contains some of my more well-developed commonThings...
The bold ones are regularly/recently updated. Some non-bold ones may be used-regularly but indirectly (e.g. hfModulation is used by heartbeat).
Some are quite old... (I've tried to eliminate the questionably-functional from this list)
General / Misc.:
- __std_wrappers - stuff from STDIO that I use in specific ways, regularly. E.G. 'serIn_nonBlock' handles reading serial-input (on your desktop PC) without twiddling its thumbs until data's available. Similarly, there's a 'stdin_nonBlock' that allows your main while-loop to run other processes while awaiting keyboard input.
- _make - Contains 'reallyCommon[2/3].mk' used by *every* project, also avr-specific makefile-snippets, etc. reallyCommon[2/3].mk is basically what makes the commonCode system possible.
- cirBuff - Circular Buffer
- avrOverride - Disable some AVR-only things for testing on a desktop PC
- bithandling - Lots of bit-manipulation stuff. LOTS
- adc - Use that AVR ADC
- adcFreeRunning - Use that AVR ADC in free-running mode
Positioning (Not limited to motors):
- gotoPoxn - These implement motion-control using coordStuff
- gotoRamped
- holdPoxn - This implements a feedback system for holding a position despite varying loads.
- motorPoxn
- xyTracker - Handle motions where every intermediate point is to be traversed (e.g. drawing a line on a screen). Has many other uses as well, and is similar to hfModulation.
- sineTravel - Create travel-plans with sinusoidal-motion, circles, arcs, etc. This is also used by gotoRamped to ramp the speed of a linear-motion
Motor Control:
- lmd18200 - H-Bridge chip
- l298 - H-Bridge chip
- hctl - Connect a quadrature encoder via the HCTL-2000 series chips
- encoderDirect - Connect a quadrature encoder
Modulation and blinking:
- heartbeat - fade/error-blink an LED and use a pushbutton
- pwm - Attempts to standardize the AVRs' PWM interface
- hfModulation - "High Frequency Modulation" similar to PWM, but toggles the output as quickly as possible to maintain the average power
Keyboards/Keypads and other input:
- hsStowawayKB - Connect a Targus Stowaway Keyboard for Handspring Visor (RS-232)
- anaButtons - Connect a button-matrix to a digital I/O via resistors and capacitor
- piezoHitDetector - Use a piezo-element to detect sharp noises and physical taps/hits
LCDs / Graphics:
- lcd - ASCII/Text LCDs
- lcdStuff - GRAPHICAL - Hsync/Vsync-based LCD displays... This works with http://hackaday.io/project/3898-my-very-first-binary-clock, also https://sites.google.com/site/geekattempts/home-1/sdramthing and originated with https://sites.google.com/site/geekattempts/home-1/drive-an-old-laptop-display-from-an-avr
- nlcd - The hacker-friendly B/W Nokia display. This is based on the widely-available code, but extends functionality like scrolling text
- colorThing - Display every displayable color on an LCD in various patterns
- charBitmap - A Bitmap-character-set
- hpglText - a simple vector-based font originally used in HP plotters/printers. This was based on the program 'hp2xx' This has been implemented in
Math:
- multDiv64
- typechg - handle changing of types (e.g. uint16->uint8) while trying to maintain the closest possible value (i.e. 512(u16) -> 255(u8))
- sineTable - a table of SINE values, in integer-form, no floats necessary.
- coordStuff - Unlimited-axes 32-bit coordinate-system
- goertz - The Goertzel-Algorithm (measure phase and magnitude of a specified frequency)
Serial/Protocols:
- midi_in - Receive and process MIDI notes, etc.
- midi_out - Transmit MIDI notes, etc.
- sysex_debug - Use MIDI SysEx to send debugging messages
- polled_ps2_host - Use a PS2 device, like a touchpad
- polled_uar - bitbanged/polled UART (Receiver-Only)
- polled_uat - bitbanged/polled UART (Transmitter-Only) (Test-Code also exists here which implements full duplex Tx/Rx via polled_uar)
- uart_in - Use the AVR U[S]ART Receiver
- uart_out - Use the AVR U[S]ART Transmitter
- usart_spi - Use the AVR USART as an SPI Master
- usi_spi - Use the ATTiny series' USI for SPI
- usi_uar - Use the ATTiny series' USI for UART (Receiver-Only)
- btbConnector - Connect a serial peripheral to a computer via a BlueToothBee, transparently to its driver
Timers and such:
- tcnter - Use a free-running timer for high-precision timing (This is used quite a bit, these days... polled_ua[r/t] use this to handle bit-banging, etc.)
- timerCommon - Attempt to standardize an interface to AVRs' timers
- tinyPLL - Start the ATTiny861/85's PLL
- delayCyc - Delay an *exact* number of cycles from 1-127 (AVR assembly)
- dmsTimer - "Deci-Millisecond" (.0001s) timer for various timing things
Starting a new project:
When I start a new AVR project, I usually start with nothing more than the 'heartbeat' test-code... This gets me running with a fading LED, a timer, and a pushbutton. (I have an LED and pushbutton attached to my SPI-programmer's "dongle", so that I only need to wire-up the AVR, power, and a programming-header). If the LED fades at 8-seconds per cycle, then I know everything's working/configured right.
From there, I move on to the 'polled_uat' test-code, at which point I have serial I/O at 9600bps. (Recently, I've leaned away from using the U[S]ART and USI peripherals, as these are device-specific. The polled_uar and polled_uat are NOT AVR-Specific, and actually have desktop-PC based test-code that allows you to simulate serial I/O with a couple keys on the keyboard. Further, the polled_uar/t can be placed on any pins, so the default is to have them attached to pins on my programmer's "dongle," as well.).
Depending on my needs, I usually steal a few lines of code from other commonThings' test-code (throw their init() and update() functions in main, and copy a few lines from their 'makefile'). Then start modifying code as-necessary.
SEE: System Design/Flow
STATUS:
I started making my commonCode available as a result of posting my 'audioThing' project. (Thanks to the Trinket Everyday-Carry Contest for the motivation!)
As part of that process, I've come up with some new and easier methods for using and distributing commonThings, some new standards as far as test-code, and more. I'm hoping to make the getting-started process more step-by-step, implement test-code in commonThings that don't have them, and more.
A *big* hurdle I've yet to figure-out is *how* to distribute it! You see there's *dozens* of commonThings, and even more I didn't list here... I wouldn't mind using something like git, and even started putting stuff up on gitHub, but that doesn't really seem to lend-itself well to the structure, here... For one thing, it means having dozens of separate repositories. Then, to make things even more confusing; how should I handle *versions*? 'heartbeat' is now at v2.02 and has about 10 *functional* versions leading up to that. For the most-part there's no reason to distribute *all* of these, but some older projects still depend on older versions... changing them over to v2+ is a big change... and there's no guarantee that v1.50 is backwards-compatible with v1.10 (though most-likely v1.19 is). You get the idea. Even if I *only* uploaded the latest versions, what when I've developed 2.50?
Unless I can find (or am directed to?) a system that lends itself to a structure like this, the best I can think is to run a custom web-server... That would be my normal path; (I tend to reinvent the wheel, but usually do-so in a way that works well for my needs while giving me a good learning-experience in the process), but these days I don't have a steady internet-connection to serve from, nor access to a server like that...
So, for now, there's a bit to be done, and a bit to ponder.
Progect Log Table Of Contents (roughly oldest to newest, some from 'the other projects'):
- breakdown of files/configs ideas - 12964-new-layout-thoughts
- potential scrapping of new file/config layout - 17442-wee
- hacklet mention - 13282-had-blog-mention-please-commentfollow
- blog mention! + Maybe the new file-layout isn't so bad... - 19480-had-blog-entry-new-followers-and-a-brief-revisit
- Maybe Git can be forced to work... - 19655-hey-coding
- Git automation attempts - 19754-gitty
- initial thoughts on abstracting code via PIC32... once simulated motion-control via openGL! - 20141-abstractn-and-picn
- 'heartbeat' running on PIC32 + video - pic32/log/20427-its-alive
- tcnter explanation + PIC32 porting/abstraction process - pic32/log/20769-wins-and-tcnter
- heartbeat, polled-uat, polled-uar ported/abstracted to pic32, now on to motion-control (detailed) - pic32/log/22496-finally
- heartbeat, polled-uat, polled-uar ported/abstracted to pic32, now on to motion-control (brief) - 22497-the-main-three-now-on-pic32
- Three Projects That Feed Into Each Other + Video of commonCode's motion-control on PIC32 - 23266-this-is-getting-confusing-video
- System Design/Flow - 23363-system-design
Licensing:
The Vast Majority of 'commonCode' and its 'commonThings' are written by me, in their entirety, and fall under my so-called 'mehPL' (included below).
Exceptions are noted in the corresponding code.
Exceptions include:
- 'nlcd' - drivers for the "hacker-friendly" Nokia LCD, whose code is based heavily on 3310_routines.c found all over the internets. Unfortunately, it's so ubiquitous I have yet to locate an original source, nor licensing info. The original author is claimed to be: "CC Dharmani, Chennai (India)" and was modified by "Michael Spiceland (http://tinkerish.com)" before my heavy modifications.
- 'hpglText' - which implements a simplistic vector-font originally used in HP Pen-Plotter. The character-set was originally part of 'HP2xx' "Copyright (c) 1992 - 1994 Heinz W. Werntges. All rights reserved. Parts Copyright (c) 1999 Martin Kroeker All rights reserved. Distributed by Free Software Foundation, Inc." "under the conditions described in the GNU General Public License."
- Also a note should be made about commonCode's original inspiration which came from the 'gcc-test' AVR 'tutorials' by Eric B. Weddington, some tiny pieces of makefile code (variable names, mainly) still remain from his work. TODO!
See the mehPL for additional gratititude!
'commonCode' was developed to make use of GPLed tools such as gcc, gnu-bash, gnu-make, etc. as well as avr-libc, etc. However, commonCode does not contain their source-code except where explicitly mentioned (again, e.g. variable/register names/dereferencing-methods found in avr/io.h, etc) TODO! Similarly, Microchip's xc32-gcc, associated tools (xc32-objdump, etc.), and header/linker files are used by-default for PIC32 devices, but these files are not included with commonCode, and must be downloaded from Microchip and installed by the user.
mehPL:
My so-called "mehPL" is listed below. There's certainly room for improvement, and I'm willing to flex on a few requirements, in light of better ideas. (Feel free to contact me with 'em!) I haven't yet fully read the GPL nor other de-facto open-source licenses, but I am pretty certain they do not include some aspects I consider essential in my willingness to share my code... Again, I'm open to being enlightened!
Currently the top of each file is noted as follows:
/* mehPL:
* This is Open Source, but NOT GPL. I call it mehPL.
* I'm not too fond of long licenses at the top of the file
* Please see the bottom.
* Enjoy!
*/
The bottom of each file is noted with the terms of the mehPL:
/* mehPL:
* I would love to believe in a world where licensing shouldn't be
* necessary; where people would respect others' work and wishes,
* and give credit where it's due.
* A world where those who find people's work useful would at least
* send positive vibes--if not an email.
* A world where we wouldn't have to think about the potential
* legal-loopholes that others may take advantage of.
*
* Until that world exists:
*
* This software and associated hardware design is free to use,
* modify, and even redistribute, etc. with only a few exceptions
* I've thought-up as-yet (this list may be appended-to, hopefully it
* doesn't have to be):
*
* 1) Please do not change/remove this licensing info.
* 2) Please do not change/remove others' credit/licensing/copyright
* info, where noted.
* 3) If you find yourself profiting from my work, please send me a
* beer, a trinket, or cash is always handy as well.
* (Please be considerate. E.G. if you've reposted my work on a
* revenue-making (ad-based) website, please think of the
* years and years of hard work that went into this!)
* 4) If you *intend* to profit from my work, you must get my
* permission, first.
* 5) No permission is given for my work to be used in Military, NSA,
* pranks, victimizations, 'hacking' of others' computers/networks,
* or other creepy-ass purposes. No exceptions. And if there's
* any question in your mind as to whether your project qualifies
* under this category, you must get my explicit permission.
*
* The open-sourced project this originated from is ~98% the work of
* the original author (me), except where otherwise noted.
* That includes the "commonCode" and makefiles.
* Thanks, of course, should be given to those who worked on the tools
* I've used: avr-dude, avr-gcc, gnu-make, vim, usb-tiny, and
* I'm certain many others.
* And, as well, to the countless coders who've taken time to post
* solutions to issues I couldn't solve, all over the internets.
*
*
* I'd love to hear of how this is being used, suggestions for
* improvements, etc!
*
* The creator of the original code and original hardware can be
* contacted at:
*
* EricWazHung At Gmail Dotcom
*
* This code's origin (and latest versions) may be found at:
*
* https://github.com/ericwazhung
* https://code.google.com/u/ericwazhung/
* https://github.com/esot-eric-test
*
* The site associated with the original open-sourced project is at:
*
* https://sites.google.com/site/geekattempts/
*
* If any of that ever changes, I will be sure to note it here,
* and add a link at the pages above.
*
* (Wow, that's a lot longer than I'd hoped).
*
* Enjoy!
*/