Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <mutek/startup.h>
#include <mutek/thread.h>
#include <mutek/printk.h>
#include <device/class/gpio.h>
#include <device/class/timer.h>
#define RS 18
#define D7 13
#define BACK 12
#define E 17
#define FIRST 12
#define LAST 18
static const uint64_t nibble_rev = 0xf7b3d591e6a2c480;
struct device_gpio_s gpio;
struct device_timer_s timer;
dev_timer_delay_t msec;
static void lcd_put(bool_t rs, uint8_t byte)
{
uint8_t val;
DEVICE_OP(&gpio, set_output, RS, RS,
rs ? dev_gpio_mask1 : dev_gpio_mask0,
rs ? dev_gpio_mask1 : dev_gpio_mask0);
val = nibble_rev >> ((byte >> 4) * 4);
DEVICE_OP(&gpio, set_output, D7, D7 + 3, &val, &val);
DEVICE_OP(&gpio, set_output, E, E, dev_gpio_mask0, dev_gpio_mask0);
dev_timer_wait_delay(&timer, msec, 0);
DEVICE_OP(&gpio, set_output, E, E, dev_gpio_mask1, dev_gpio_mask1);
dev_timer_wait_delay(&timer, msec, 0);
val = nibble_rev >> ((byte & 0xf) * 4);
DEVICE_OP(&gpio, set_output, D7, D7 + 3, &val, &val);
DEVICE_OP(&gpio, set_output, E, E, dev_gpio_mask0, dev_gpio_mask0);
dev_timer_wait_delay(&timer, msec, 0);
DEVICE_OP(&gpio, set_output, E, E, dev_gpio_mask1, dev_gpio_mask1);
dev_timer_wait_delay(&timer, msec, 0);
}
static void lcd_put_string(char *str)
{
while (*str)
lcd_put(1, *str++);
}
static CONTEXT_ENTRY(lcd_hello)
{
lcd_put(0, 0x33);
dev_timer_wait_delay(&timer, msec * 4, 0);
lcd_put(0, 0x33);
dev_timer_wait_delay(&timer, msec * 4, 0);
lcd_put(0, 0x32);
lcd_put(0, 0x28);
lcd_put(0, 0x08);
lcd_put(0, 0x01);
lcd_put(0, 0x06);
lcd_put(0, 0x0c);
lcd_put_string("Hello,");
lcd_put(0, 0xc0);
lcd_put_string("world !");
}
void app_start()
{
error_t err;
printk("Hello World!\n");
err = device_get_accessor_by_path(&gpio.base, NULL, "/gpio*", DRIVER_CLASS_GPIO);
assert(!err);
err = device_get_accessor_by_path(&timer.base, NULL, "/rtc*", DRIVER_CLASS_TIMER);
assert(!err);
DEVICE_OP(&gpio, set_output, FIRST, LAST, dev_gpio_mask1, dev_gpio_mask1);
DEVICE_OP(&gpio, set_output, BACK, BACK, dev_gpio_mask0, dev_gpio_mask0);
DEVICE_OP(&gpio, set_mode, FIRST, LAST, dev_gpio_mask1, DEV_PIN_PUSHPULL);
dev_timer_init_sec(&timer, &msec, 0, 1, 1000);
thread_create(lcd_hello, 0, NULL);
}