adapted code to use the wintype.h types and the error codes
This commit is contained in:
parent
0849582c7b
commit
09f4b5ceb5
34
src/fbinit.c
34
src/fbinit.c
|
@ -8,35 +8,39 @@
|
|||
#include <linux/fb.h>
|
||||
#include "log.h"
|
||||
#include "fbinit.h"
|
||||
#include "scode.h"
|
||||
|
||||
static int fb_fd = -1;
|
||||
|
||||
static FBINFO local_info;
|
||||
PCFBINFO Fb_Info = &local_info;
|
||||
|
||||
uint16_t *Fb_Ptr = NULL;
|
||||
UINT16 *Fb_Ptr = NULL;
|
||||
|
||||
inline static unsigned makemask(unsigned offset, unsigned length)
|
||||
inline static UINT16 makemask(unsigned offset, unsigned length)
|
||||
{
|
||||
return ((1 << length) - 1) << offset;
|
||||
return (UINT16)(((1 << length) - 1) << offset);
|
||||
}
|
||||
|
||||
int Fb_setup(void)
|
||||
HRESULT Fb_setup(void)
|
||||
{
|
||||
HRESULT hr = S_OK;
|
||||
struct fb_fix_screeninfo fixed;
|
||||
struct fb_var_screeninfo var;
|
||||
|
||||
fb_fd = open("/dev/fb1", O_RDWR);
|
||||
if (fb_fd == -1)
|
||||
{
|
||||
Log(LFATAL, "Unable to open framebuffer (%d)", errno);
|
||||
return -1;
|
||||
hr = ERRNO_AS_SCODE;
|
||||
Log(LFATAL, "Unable to open framebuffer (%08X)", hr);
|
||||
return hr;
|
||||
}
|
||||
|
||||
if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fixed))
|
||||
{
|
||||
Log(LFATAL, "Could not get fixed screen info (%d)", errno);
|
||||
return -1;
|
||||
hr = ERRNO_AS_SCODE;
|
||||
Log(LFATAL, "Could not get fixed screen info (%08X)", hr);
|
||||
return hr;
|
||||
}
|
||||
|
||||
local_info.linebytes = fixed.line_length;
|
||||
|
@ -44,8 +48,9 @@ int Fb_setup(void)
|
|||
|
||||
if (ioctl(fb_fd, FBIOGET_VSCREENINFO, &var))
|
||||
{
|
||||
Log(LFATAL, "Could not get variable screen info (%d)", errno);
|
||||
return -1;
|
||||
hr = ERRNO_AS_SCODE;
|
||||
Log(LFATAL, "Could not get variable screen info (%08X)", hr);
|
||||
return hr;
|
||||
}
|
||||
|
||||
local_info.width = var.xres;
|
||||
|
@ -63,19 +68,20 @@ int Fb_setup(void)
|
|||
local_info.blue_length = var.blue.length;
|
||||
local_info.blue_mask = makemask(var.blue.offset, var.blue.length);
|
||||
|
||||
Fb_Ptr = (uint16_t *)mmap(0, fixed.smem_len, PROT_READ|PROT_WRITE, MAP_SHARED, fb_fd, 0);
|
||||
Fb_Ptr = (UINT16 *)mmap(0, fixed.smem_len, PROT_READ|PROT_WRITE, MAP_SHARED, fb_fd, 0);
|
||||
if ((int)Fb_Ptr == -1)
|
||||
{
|
||||
Log(LFATAL, "Unable to memmap framebuffer (%d)", errno);
|
||||
hr = ERRNO_AS_SCODE;
|
||||
Log(LFATAL, "Unable to memmap framebuffer (%08X)", hr);
|
||||
Fb_Ptr = NULL;
|
||||
close(fb_fd);
|
||||
fb_fd = -1;
|
||||
return -1;
|
||||
return hr;
|
||||
}
|
||||
|
||||
/* additional setup here */
|
||||
|
||||
return 0;
|
||||
return hr;
|
||||
}
|
||||
|
||||
void Fb_cleanup(void)
|
||||
|
|
38
src/fbinit.h
38
src/fbinit.h
|
@ -1,32 +1,32 @@
|
|||
#ifndef __FBINIT_H_INCLUDED
|
||||
#define __FBINIT_H_INCLUDED
|
||||
|
||||
#include <stdint.h>
|
||||
#include "wintype.h"
|
||||
|
||||
typedef struct tagFBINFO {
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t virtual_width;
|
||||
uint32_t virtual_height;
|
||||
uint32_t bpp;
|
||||
uint32_t linebytes;
|
||||
uint32_t screenbytes;
|
||||
uint16_t red_offset;
|
||||
uint16_t red_length;
|
||||
uint16_t red_mask;
|
||||
uint16_t green_offset;
|
||||
uint16_t green_length;
|
||||
uint16_t green_mask;
|
||||
uint16_t blue_offset;
|
||||
uint16_t blue_length;
|
||||
uint16_t blue_mask;
|
||||
UINT32 width;
|
||||
UINT32 height;
|
||||
UINT32 virtual_width;
|
||||
UINT32 virtual_height;
|
||||
UINT32 bpp;
|
||||
UINT32 linebytes;
|
||||
UINT32 screenbytes;
|
||||
UINT16 red_offset;
|
||||
UINT16 red_length;
|
||||
UINT16 red_mask;
|
||||
UINT16 green_offset;
|
||||
UINT16 green_length;
|
||||
UINT16 green_mask;
|
||||
UINT16 blue_offset;
|
||||
UINT16 blue_length;
|
||||
UINT16 blue_mask;
|
||||
} FBINFO;
|
||||
typedef const FBINFO * const PCFBINFO;
|
||||
|
||||
extern PCFBINFO Fb_Info;
|
||||
extern uint16_t *Fb_Ptr;
|
||||
extern UINT16 *Fb_Ptr;
|
||||
|
||||
extern int Fb_setup(void);
|
||||
extern HRESULT Fb_setup(void);
|
||||
extern void Fb_cleanup(void);
|
||||
|
||||
#endif /* __FBINIT_H_INCLUDED */
|
||||
|
|
13
src/gpio.c
13
src/gpio.c
|
@ -1,6 +1,7 @@
|
|||
#include <stdint.h>
|
||||
#include <bcm2835.h>
|
||||
#include "log.h"
|
||||
#include "scode.h"
|
||||
#include "gpio.h"
|
||||
|
||||
#define GLINE_BUTTON1 17
|
||||
|
@ -11,12 +12,12 @@
|
|||
|
||||
#define PWM_BACKLIGHT 0
|
||||
|
||||
int Gpio_setup(void)
|
||||
HRESULT Gpio_setup(void)
|
||||
{
|
||||
if (!bcm2835_init())
|
||||
{
|
||||
Log(LFATAL, "Error initializing BCM2835 library");
|
||||
return -1;
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
/* configure the buttons */
|
||||
|
@ -37,7 +38,7 @@ int Gpio_setup(void)
|
|||
bcm2835_pwm_set_range(PWM_BACKLIGHT, GSB_BACKLIGHT_MAX + 1);
|
||||
bcm2835_pwm_set_data(PWM_BACKLIGHT, GSB_BACKLIGHT_MAX);
|
||||
|
||||
return 0;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void Gpio_cleanup(void)
|
||||
|
@ -61,9 +62,9 @@ void Gpio_cleanup(void)
|
|||
Log(LWARN, "Closing BCM2835 library failed");
|
||||
}
|
||||
|
||||
int Gpio_read_buttons(void)
|
||||
UINT32 Gpio_read_buttons(void)
|
||||
{
|
||||
int rc = 0;
|
||||
UINT32 rc = 0;
|
||||
|
||||
if (bcm2835_gpio_lev(GLINE_BUTTON1) == LOW)
|
||||
rc |= GRB_STATE_BUTTON1;
|
||||
|
@ -76,7 +77,7 @@ int Gpio_read_buttons(void)
|
|||
return rc;
|
||||
}
|
||||
|
||||
void Gpio_set_backlight(unsigned level)
|
||||
void Gpio_set_backlight(UINT32 level)
|
||||
{
|
||||
if (level > GSB_BACKLIGHT_MAX)
|
||||
level = GSB_BACKLIGHT_MAX;
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef __GPIO_H_INCLUDED
|
||||
#define __GPIO_H_INCLUDED
|
||||
|
||||
#include "wintype.h"
|
||||
|
||||
#define GPIO_BUTTON_COUNT 4
|
||||
|
||||
#define GRB_STATE_BUTTON1 (1 << 0)
|
||||
|
@ -10,9 +12,9 @@
|
|||
|
||||
#define GSB_BACKLIGHT_MAX 1023
|
||||
|
||||
extern int Gpio_setup(void);
|
||||
extern HRESULT Gpio_setup(void);
|
||||
extern void Gpio_cleanup(void);
|
||||
extern int Gpio_read_buttons(void);
|
||||
extern void Gpio_set_backlight(unsigned level);
|
||||
extern UINT32 Gpio_read_buttons(void);
|
||||
extern void Gpio_set_backlight(UINT32 level);
|
||||
|
||||
#endif /* __GPIO_H_INCLUDED */
|
||||
|
|
13
src/main.c
13
src/main.c
|
@ -1,5 +1,6 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "scode.h"
|
||||
#include "gpio.h"
|
||||
#include "log.h"
|
||||
#include "fbinit.h"
|
||||
|
@ -13,9 +14,9 @@ static void do_draw(void)
|
|||
memset(tmp, 0xFF, Fb_Info->screenbytes / 2);
|
||||
memset(tmp + (Fb_Info->screenbytes / 2), 0x1B, Fb_Info->screenbytes / 2);
|
||||
*/
|
||||
uint16_t pixel = Fb_Info->green_mask;
|
||||
unsigned npix = Fb_Info->screenbytes / sizeof(uint16_t);
|
||||
uint16_t *p = Fb_Ptr;
|
||||
UINT16 pixel = Fb_Info->green_mask;
|
||||
unsigned npix = Fb_Info->screenbytes / sizeof(UINT16);
|
||||
UINT16 *p = Fb_Ptr;
|
||||
unsigned i;
|
||||
|
||||
for (i=0; i<npix; i++)
|
||||
|
@ -29,13 +30,13 @@ int main(int argc, char *argv[])
|
|||
char *tmp;
|
||||
|
||||
Time_init();
|
||||
if (Fb_setup() != 0)
|
||||
if (FAILED(Fb_setup()))
|
||||
return EXIT_FAILURE;
|
||||
atexit(Fb_cleanup);
|
||||
if (Gpio_setup() != 0)
|
||||
if (FAILED(Gpio_setup()))
|
||||
return EXIT_FAILURE;
|
||||
atexit(Gpio_cleanup);
|
||||
if (Sys_enable_input() != 0)
|
||||
if (FAILED(Sys_enable_input()))
|
||||
return EXIT_FAILURE;
|
||||
atexit(Sys_disable_input);
|
||||
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
#define MSG_ATTRCOUNT 2
|
||||
|
||||
typedef struct tagMSG {
|
||||
uintptr_t target;
|
||||
unsigned message;
|
||||
uintptr_t attrs[MSG_ATTRCOUNT];
|
||||
HANDLE target;
|
||||
UINT32 message;
|
||||
UINT_PTR attrs[MSG_ATTRCOUNT];
|
||||
TIMESTAMP timestamp;
|
||||
} MSG, *PMSG;
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include "time_func.h"
|
||||
#include "msg_queue.h"
|
||||
|
||||
PMSG_QUEUE Mq_alloc(int nentries)
|
||||
PMSG_QUEUE Mq_alloc(UINT32 nentries)
|
||||
{
|
||||
int sz = sizeof(MSG_QUEUE) + (nentries * sizeof(MSG));
|
||||
PMSG_QUEUE rc;
|
||||
|
@ -46,7 +46,7 @@ static void post_internal(PMSG_QUEUE queue, PMSG msg)
|
|||
pthread_mutex_unlock(&(queue->mutex));
|
||||
}
|
||||
|
||||
void Mq_post(PMSG_QUEUE queue, uintptr_t target, unsigned message, const uintptr_t *attrs, int nattrs)
|
||||
void Mq_post(PMSG_QUEUE queue, HANDLE target, UINT32 message, const UINT_PTR *attrs, int nattrs)
|
||||
{
|
||||
MSG tmpmsg;
|
||||
|
||||
|
@ -61,7 +61,7 @@ void Mq_post(PMSG_QUEUE queue, uintptr_t target, unsigned message, const uintptr
|
|||
post_internal(queue, &tmpmsg);
|
||||
}
|
||||
|
||||
void Mq_post1(PMSG_QUEUE queue, uintptr_t target, unsigned message, uintptr_t attr1)
|
||||
void Mq_post1(PMSG_QUEUE queue, HANDLE target, UINT32 message, UINT_PTR attr1)
|
||||
{
|
||||
MSG tmpmsg;
|
||||
|
||||
|
@ -73,9 +73,9 @@ void Mq_post1(PMSG_QUEUE queue, uintptr_t target, unsigned message, uintptr_t at
|
|||
post_internal(queue, &tmpmsg);
|
||||
}
|
||||
|
||||
int Mq_peek(PMSG_QUEUE queue, PMSG msg, unsigned flags)
|
||||
BOOL Mq_peek(PMSG_QUEUE queue, PMSG msg, UINT32 flags)
|
||||
{
|
||||
int rc = 0;
|
||||
BOOL rc = FALSE;
|
||||
PMSG nexthead;
|
||||
|
||||
pthread_mutex_lock(&(queue->mutex));
|
||||
|
@ -87,7 +87,7 @@ int Mq_peek(PMSG_QUEUE queue, PMSG msg, unsigned flags)
|
|||
memcpy(msg, queue->head, sizeof(MSG));
|
||||
if (flags & PEEK_REMOVE)
|
||||
queue->head = nexthead;
|
||||
rc = 1;
|
||||
rc = TRUE;
|
||||
}
|
||||
pthread_mutex_unlock(&(queue->mutex));
|
||||
return rc;
|
||||
|
|
|
@ -10,7 +10,7 @@ typedef struct tagMSG_QUEUE {
|
|||
PMSG endbound;
|
||||
PMSG head;
|
||||
PMSG tail;
|
||||
int nentries;
|
||||
UINT32 nentries;
|
||||
pthread_mutex_t mutex;
|
||||
MSG messagestore[0];
|
||||
} MSG_QUEUE, *PMSG_QUEUE;
|
||||
|
@ -18,10 +18,10 @@ typedef struct tagMSG_QUEUE {
|
|||
#define PEEK_REMOVE 0x0001
|
||||
#define PEEK_NOREMOVE 0x0000
|
||||
|
||||
extern PMSG_QUEUE Mq_alloc(int nentries);
|
||||
extern PMSG_QUEUE Mq_alloc(UINT32 nentries);
|
||||
extern void Mq_destroy(PMSG_QUEUE queue);
|
||||
extern void Mq_post(PMSG_QUEUE queue, uintptr_t target, unsigned message, const uintptr_t *attrs, int nattrs);
|
||||
extern void Mq_post1(PMSG_QUEUE queue, uintptr_t target, unsigned message, uintptr_t attr1);
|
||||
extern int Mq_peek(PMSG_QUEUE queue, PMSG msg, unsigned flags);
|
||||
extern void Mq_post(PMSG_QUEUE queue, HANDLE target, UINT32 message, const UINT_PTR *attrs, int nattrs);
|
||||
extern void Mq_post1(PMSG_QUEUE queue, HANDLE target, UINT32 message, UINT_PTR attr1);
|
||||
extern BOOL Mq_peek(PMSG_QUEUE queue, PMSG msg, UINT32 flags);
|
||||
|
||||
#endif /* __MSG_QUEUE_H_INCLUDED */
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef __SCODE_H_INCLUDED
|
||||
#define __SCODE_H_INCLUDED
|
||||
|
||||
#include <wintype.h>
|
||||
#include "wintype.h"
|
||||
|
||||
/*-------------------------------------------------------------------
|
||||
* Status codes are defined as follows:
|
||||
|
@ -37,7 +37,8 @@
|
|||
|
||||
#define MAKE_SCODE(sev, fac, err) ((SCODE)((sev) | (((fac) & 0x7FFF) << 16) | ((err) & 0xFFFF)))
|
||||
|
||||
#define ERRNO_AS_SCODE MAKE_SCODE(SEVERITY_ERROR, FACILITY_UNIX, errno)
|
||||
#define SCODE_FROM_ERRNO(x) MAKE_SCODE(SEVERITY_ERROR, FACILITY_UNIX, (x))
|
||||
#define ERRNO_AS_SCODE SCODE_FROM_ERRNO(errno)
|
||||
|
||||
#define SCODE_CAST(x) ((SCODE)(x))
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include <stddef.h>
|
||||
#include <signal.h>
|
||||
#include <pthread.h>
|
||||
#include "scode.h"
|
||||
#include "log.h"
|
||||
#include "msg_queue.h"
|
||||
#include "gpio.h"
|
||||
|
@ -9,12 +10,12 @@ PMSG_QUEUE Sys_Queue = NULL;
|
|||
|
||||
static pthread_t ithread;
|
||||
static volatile sig_atomic_t running = 1;
|
||||
static int last_bstate = 0;
|
||||
static UINT32 last_bstate = 0;
|
||||
|
||||
static void *input_thread(void *arg)
|
||||
{
|
||||
int st, down, up, mask;
|
||||
uintptr_t attr;
|
||||
UINT32 st, down, up, mask;
|
||||
UINT_PTR attr;
|
||||
|
||||
while (running)
|
||||
{
|
||||
|
@ -39,20 +40,24 @@ static void *input_thread(void *arg)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
int Sys_enable_input(void)
|
||||
HRESULT Sys_enable_input(void)
|
||||
{
|
||||
int rc;
|
||||
HRESULT rc = S_OK;
|
||||
int threadrc;
|
||||
|
||||
Sys_Queue = Mq_alloc(64);
|
||||
if (!Sys_Queue)
|
||||
{
|
||||
Log(LFATAL, "Unable to allocate system message queue.");
|
||||
return 1;
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
running = 1;
|
||||
rc = pthread_create(&ithread, NULL, input_thread, NULL);
|
||||
if (rc != 0)
|
||||
Log(LFATAL, "Unable to start system input thread (%d).", rc);
|
||||
threadrc = pthread_create(&ithread, NULL, input_thread, NULL);
|
||||
if (threadrc != 0)
|
||||
{
|
||||
rc = SCODE_FROM_ERRNO(threadrc);
|
||||
Log(LFATAL, "Unable to start system input thread (%08X).", rc);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
#ifndef __SYSINPUT_H_INCLUDED
|
||||
#define __SYSINPUT_H_INCLUDED
|
||||
|
||||
#include "wintype.h"
|
||||
#include "msg_queue.h"
|
||||
|
||||
extern PMSG_QUEUE Sys_Queue;
|
||||
|
||||
extern int Sys_enable_input(void);
|
||||
extern HRESULT Sys_enable_input(void);
|
||||
extern void Sys_disable_input(void);
|
||||
|
||||
#endif /* __SYSINPUT_H_INCLUDED */
|
||||
|
|
Loading…
Reference in New Issue
Block a user