| Posted: 04:26pm 15 Oct 2018 |
Copy link to clipboard |
 Print this post |
|
perfect !. thanks. I studied the MZ datasheet a bit and there are actually 6 I2c controllers. all identical , just with offsets. The current i2c code is pretty convoluted ( i have the C sourcecode) and i'm thinking of writing a basic library that is portable between the channels. you just provide the channel and the code uses different offsets.
I am trying to port an existing hardware project from Teensy to the Extreme version. I use a capacitive touch screen (as opposed to resistive which looks dull and reduces luminosity of the panel) and i use one i2c bus for internal household : buttons, led's , navipad (rotary encoder with 5 way tactile pad). battery backed RTC , battery gauge / charger and more stuff.
The hardware is open source and posted on Circuitmaker hub. I wanted callbacks because my architecture is so that there is one system interrupt that needs servicing. This interrupt will generate events like key<x>_[down/up/click] where key is [up/down/left/right/a/b/c/standby/select] rotary.[increment/decrement/lowlimit/highlimit/change]
The rotary encoder uses a table so i can dynamically switch what variable is controlled by it without user interaction.
const value1 1 const value2 2
' Setup this variable so that data lies between lower and upper bound in steps of 1. whenever the encoder is manipulated we get an interrupt ( if the encoder is currently'bound' to the variable.)
rotary(value1).lowerbound = 4 rotary(value1).upperbound = 9 rotary(value1).interrupt = always rotary(value1).step = 1
' Setup this variable so that data lies between lower and upper bound in steps of 0.1. We only get an interrupt if data has changed AND the encoder is clicked (center button) or we hit zero. other possible interrupt scenarios : on_increment, on_decrement, on_max,on_min,on_zero. this is a bitfield so it can be or-ed together.
rotary(value2).lowerbound = -2 rotary(value2).upperbound = +2 rotary(value2).step = 0.1 rotary(value2).interrupt = on_confirm | on_zero rotary(value2).handler = addressof (value2_handler)
rotary.select(value2) ' binds the encoder to value2. whenever the user turns the data updates and an event fires
sub value2_handler(eventmask) ..... if (eventmask and on_zero) then print "zero !" if (eventmask and on_confirm) then print "new value : ", rotary.currentvalue end sub

 |