Device IO Library
blittled
Posts: 681
In building some demos I see myself repeating routines especially in masking bits so I thought a library of functions would be useful. The code would be in C, no assembly, so some functions maybe somewhat slow but portable between most memory models and also independent of board type. Most of the routines are built from other functions in the library and is modeled after the BS2_Functions. Right now I have the following:
void Out(int pin, int state)
This sets DIRA for the pin as an output then sets it to state.
int In(int pin)
This sets DIRA for the pin as an input and returns the state of input
void Delay(uint32_t duration)
This waits duration counts of CLK.
void Pulse(int pin, int state, uint32_t duration)
This pulses a pin for duration counts at the state designated then sets the pin to the opposite state
I'm now working on shiftin and shiftout on a pin.
I have plans for PWMPin, FreqOut, CountPulses, SerOut, SerIn, I2CWrite, I2CRead, SPIByte, SPIWord, SPILong.
Does anyone have any other suggestions?
My primary goal with this is to provide code examples for beginning C programmers and have functions that make the transition from SPIN to C easier. I also plan on coding some demos that use the library. Due to the holidays my schedule is a bit busy. I'm squeezing in time for this project when I can so it may be a little while before it is finished.
void Out(int pin, int state)
This sets DIRA for the pin as an output then sets it to state.
int In(int pin)
This sets DIRA for the pin as an input and returns the state of input
void Delay(uint32_t duration)
This waits duration counts of CLK.
void Pulse(int pin, int state, uint32_t duration)
This pulses a pin for duration counts at the state designated then sets the pin to the opposite state
I'm now working on shiftin and shiftout on a pin.
I have plans for PWMPin, FreqOut, CountPulses, SerOut, SerIn, I2CWrite, I2CRead, SPIByte, SPIWord, SPILong.
Does anyone have any other suggestions?
My primary goal with this is to provide code examples for beginning C programmers and have functions that make the transition from SPIN to C easier. I also plan on coding some demos that use the library. Due to the holidays my schedule is a bit busy. I'm squeezing in time for this project when I can so it may be a little while before it is finished.
Comments
I haven't really looked at the effort required to port the library.
It's all open source and has some of the same function names.
Having a simple library like you mention has value too.
I'm not trying to dissuade you as any effort is appreciated.
Enthusiastic second on this idea! I'm eager to provide what resources I can to help in this effort.
Maybe it's a good idea to port the LegOS, with lib functions like
void PlaySound(int frequency, int duration)
void motor_a_dir (MotorDirection dir)
void motor_a_speed(unsigned char speed)
wakeup_t wait_event ((*'wakeup) ......)
That are all functions for robotic environment, what's the forum think about this , replace the Brick with an propeller board ?
some nice sensors in the lego kit
In this time I used the LegOS instead the original Operating System.
I must search this old stuff, because today I have no idea about the Memory Size.
Maybe it's too large for the hub, but perhaps any can make a tailor made solution.
I'll go back if I found more details.
Reinhard
I think the IO Lib from bittled, will be a good base for any project.
With the Arduino I am not so familiar, so I can nothing say about it.
Reinhard
Will give a small input for library.
For analog input reading with a SigmaDelta ADC, according to Parallax AN008,
here is the C version.
best regards
Reinhard
The RCX1.0 has a Hitachi H8 µC with 32 kB RAM.
So I start with the Robot Library.
First Implementation include
void setMotorPower (Motor motor, Power percent); // motor = A | B | C percent = 0 .. 100
void setMotorDirection (Motor motor, Direction dir); // dir = fwd | back
I build a Breadboard with an Propstick/USB and own electronic circuit driver for the origin Lego motors / sensors.
Will present if finished, maybe after xmas holidays.
best regards
Reinhard
the Robot Project makes good progress.
Today afternoon I build first prototype, looks like this:
Pinning: Controlled by needed Header
P0 currently unused
P1 currently unused
P2 currently unused
P3 AnalogOut Duty Cycle Method Cog0 analog_out.h
P4 MotorB direction Digital Out Cog0 motor.h / kernel.h
P5 MotorA direction Digital Out Cog0 motor.h / kernel.h
P6 MotorB Power PWM Cog1 motor.h / kernel.h
P7 MotorA Power PWM Cog2 motor.h / kernel.h
P8/P9 AnalogInSlow SigmaDelta Cog3 kernel.h
P10 currently unused
P11 currently unused
P12 currently unused
P13 currently unused
P14 currently unused
P15 currently unused
P16 LED DigitalOut Cog0
P17 currently unused
P18 currently unused
P19 currently unused
P20 currently unused
P21 currently unused
P22 currently unused
P23 currently unused
P24 currently unused
P25 currently unused
P26 currently unused
P27 currently unused
P28 SCL EEPROM
P29 SDA EEPROM
P30 RXD USB
P31 TXD USB
Planned:
ADC_Fast MAX147 via 4 wire Interface
LCD_Display Hitachi LCD Interface
Sound_OUT Play a Melody
Touch Sensor Digital IN
LightSensor Channel 0 of MAX 147
IR Sensor Channel 1 of MAX 147
Hall Sensor Channel 2 of MAX 147
best regards,
Reinhard
The Shift In and Shift Out use a clock that should be about 40kHz. I'll verify it with an oscilloscope. I may be able to tweak it for a faster speed.
I am now working with I2C functions and plan on developing SPI and Serial protocols. Then I'll concentrate on the cog clocks so I can produce PWM, Pulse width measurement and measuring time between pulses.
Once these are done I'll zip up the library with all my test programs to devices as demos and a pdf describing the library functions and demos.
After that I'll probably rewrite the pdf as a tutorial teaching how to transition from Spin to C. And if I feel ambitious I'll rewrite the code in C++.
Cheers,
Eric