I am a newbie to C and Rpi in general and i was looking a round a lot to understand how can i use the UART on Rpi in bare metal C programing to make the user able to change the value of variables in the code from the terminal of Ubuntu.
My program is an RGB LED dimmer, I wrote it to give the RGB led "breathing" effect. fade in and fade out slowly.
I am trying now to dimm the different colors from the keyboard and display some kind of message on the terminal to show user interaction, I am using raspbootcom(1) to send the Kernel.img to the Rpi, and as i read it leaves a channel open for all input and output communication through something called STDIN and STDOUT, but i have no idea how or what to write in the code to manage to send values into variables and display output on the screen, given that any library i Include gets rejected by the gcc compiler.
I knw this might be very general and not detailed question but I am lost and i have a deadline to meet to be able to finish this course.
Thanks a lot for your help
(1)https://github.com/mrvn/raspbootin
This is my code:
Code: Select all
#include <stdint.h>
#define GPIO_FSEL_ADDR 0x20200000
#define GPSET0_OFFS 28
#define GPCLR0_OFFS 40
#define GPFSEL1_OFFS1 8
#define LED_BIT_SET1 9
#define GPIO_PIN_OFFS1 23
#define GPFSEL1_OFFS2 8
#define LED_BIT_SET2 12
#define GPIO_PIN_OFFS2 24
#define GPFSEL1_OFFS3 8
#define LED_BIT_SET3 15
#define GPIO_PIN_OFFS3 25
#define mmio32(x) (*(volatile uint32_t*) (x))
volatile uint32_t tim;
volatile uint32_t l = 3000;
volatile uint32_t h = 1;
int main()
{
//set as output
mmio32(GPIO_FSEL_ADDR + GPFSEL1_OFFS1) |= (1<<LED_BIT_SET1);
mmio32(GPIO_FSEL_ADDR + GPFSEL1_OFFS2) |= (1<<LED_BIT_SET2);
mmio32(GPIO_FSEL_ADDR + GPFSEL1_OFFS3) |= (1<<LED_BIT_SET3);
while (10)
{
//fade in blue
if (h < 10)
{
do
{
h += 1;
l -= 1;
// switch on led
mmio32(GPIO_FSEL_ADDR + GPCLR0_OFFS) |= (1<<GPIO_PIN_OFFS1);
// wait 1
for(tim = 0; tim < l; tim ++);
// switch off led
mmio32(GPIO_FSEL_ADDR + GPSET0_OFFS) |= (1<<GPIO_PIN_OFFS1);
// wait 2
for(tim = 0; tim < h; tim ++);
}while(h < 3000);
}
//fade out blue
if (l < 10)
{
do
{
l += 1;
h -= 1;
// switch on led
mmio32(GPIO_FSEL_ADDR + GPCLR0_OFFS) |= (1<<GPIO_PIN_OFFS1);
// wait 1
for(tim = 0; tim < l; tim ++);
// switch off led
mmio32(GPIO_FSEL_ADDR + GPSET0_OFFS) |= (1<<GPIO_PIN_OFFS1);
// wait 2
for(tim = 0; tim < h; tim ++);
}while(l < 2999);
}
//fade in green
if (h < 3000) //h is the Low wave part
{
h += 1;
l -= 1;
// switch on led
mmio32(GPIO_FSEL_ADDR + GPCLR0_OFFS) |= (1<<GPIO_PIN_OFFS2);
// wait 1
for(tim = 0; tim < l; tim ++);
// switch off led
mmio32(GPIO_FSEL_ADDR + GPCLR0_OFFS) |= (1<<GPIO_PIN_OFFS2);
// wait 2
for(tim = 0; tim < h; tim ++);
}
//fade out green
if (l < 10)
{
do
{
l += 1;
h -= 1;
// switch on led
mmio32(GPIO_FSEL_ADDR + GPCLR0_OFFS) |= (1<<GPIO_PIN_OFFS2);
// wait 1
for(tim = 0; tim < l; tim ++);
// switch off led
mmio32(GPIO_FSEL_ADDR + GPSET0_OFFS) |= (1<<GPIO_PIN_OFFS2);
// wait 2
for(tim = 0; tim < h; tim ++);
}while(l < 2999);
}
// fade in red
if (h < 3000) //h is the Low wave part
{
h += 1;
l -= 1;
// switch on led
mmio32(GPIO_FSEL_ADDR + GPCLR0_OFFS) |= (1<<GPIO_PIN_OFFS3);
// wait 1
for(tim = 0; tim < l; tim ++);
// switch off led
mmio32(GPIO_FSEL_ADDR + GPSET0_OFFS) |= (1<<GPIO_PIN_OFFS3);
// wait 2
for(tim = 0; tim < h; tim ++);
}
//fade our red
if (l < 10)
{
do
{
l += 1;
h -= 1;
// switch on led
mmio32(GPIO_FSEL_ADDR + GPCLR0_OFFS) |= (1<<GPIO_PIN_OFFS3);
// wait 1
for(tim = 0; tim < l; tim ++);
// switch off led
mmio32(GPIO_FSEL_ADDR + GPSET0_OFFS) |= (1<<GPIO_PIN_OFFS3);
// wait 2
for(tim = 0; tim < h; tim ++);
}while(l < 2999);
}
}
}