#include #include #include #include #include #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); }