File indexing completed on 2025-05-11 08:22:49
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <stdlib.h>
0010 #include <stdio.h>
0011 #include <errno.h>
0012 #include <sys/types.h>
0013 #include <pthread.h>
0014 #include <string.h>
0015
0016 #include <pxa255.h>
0017 #include <bsp.h>
0018 #include <rtems/libio.h>
0019 #include <rtems/bspIo.h>
0020
0021 #include <rtems.h>
0022 #include <rtems/inttypes.h>
0023 #include <rtems/fb.h>
0024 #include <rtems/framebuffer.h>
0025
0026 #define SCREEN_WIDTH 640
0027 #define SCREEN_HEIGHT 480
0028 #define BPP 16
0029 #define LCD_DMA_POINTER (0xa0000000 + 62*(1<<20) + 0x1000)
0030 #define LCD_BUFFER_SIZE (SCREEN_WIDTH*SCREEN_HEIGHT*2)
0031
0032
0033 pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
0034
0035 static struct fb_var_screeninfo fb_var =
0036 {
0037 .xres = SCREEN_WIDTH,
0038 .yres = SCREEN_HEIGHT,
0039 .bits_per_pixel = BPP
0040 };
0041
0042 static struct fb_fix_screeninfo fb_fix =
0043 {
0044 .smem_start = (volatile char *)LCD_DMA_POINTER,
0045 .smem_len = LCD_BUFFER_SIZE,
0046 .type = FB_TYPE_PACKED_PIXELS,
0047 .visual = FB_VISUAL_TRUECOLOR,
0048 .line_length = SCREEN_WIDTH * (BPP/8)
0049 };
0050
0051 static uint16_t red16[] = {
0052 0x0000, 0x0000, 0x0000, 0x0000, 0xaaaa, 0xaaaa, 0xaaaa, 0xaaaa,
0053 0x5555, 0x5555, 0x5555, 0x5555, 0xffff, 0xffff, 0xffff, 0xffff
0054 };
0055 static uint16_t green16[] = {
0056 0x0000, 0x0000, 0xaaaa, 0xaaaa, 0x0000, 0x0000, 0x5555, 0xaaaa,
0057 0x5555, 0x5555, 0xffff, 0xffff, 0x5555, 0x5555, 0xffff, 0xffff
0058 };
0059 static uint16_t blue16[] = {
0060 0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x0000, 0xaaaa, 0x0000, 0xaaaa,
0061 0x5555, 0xffff, 0x5555, 0xffff, 0x5555, 0xffff, 0x5555, 0xffff
0062 };
0063
0064 static void enable_fbskyeye(void)
0065 {
0066 LCCR1 &= ~LCCR1_PPL;
0067 LCCR1 |= (SCREEN_WIDTH -1 ) & LCCR1_PPL;
0068 LCCR2 &= ~LCCR2_LPP;
0069 LCCR2 |= (SCREEN_HEIGHT/2 -1) & LCCR2_LPP;
0070 LCCR3 &= ~LCCR3_BPP;
0071 LCCR3 |= 4<<24;
0072 FDADR0 = LCD_DMA_POINTER - 0x1000;
0073 LCCR0 |= LCCR0_ENB;
0074 }
0075
0076
0077 static void disable_fbskyeye(void)
0078 {
0079 LCCR0 &= ~LCCR0_ENB;
0080 }
0081
0082 static int get_fix_screen_info( struct fb_fix_screeninfo *info )
0083 {
0084 *info = fb_fix;
0085 return 0;
0086 }
0087
0088 static int get_var_screen_info( struct fb_var_screeninfo *info )
0089 {
0090 *info = fb_var;
0091 return 0;
0092 }
0093
0094 rtems_device_driver
0095 frame_buffer_initialize(rtems_device_major_number major,
0096 rtems_device_minor_number minor,
0097 void *arg)
0098 {
0099 rtems_status_code status;
0100
0101 printk( "FBSKYEYE -- driver initializing..\n" );
0102
0103
0104
0105 status = rtems_io_register_name (FRAMEBUFFER_DEVICE_0_NAME, major, 0);
0106 if (status != RTEMS_SUCCESSFUL)
0107 {
0108 printk("Error registering FBSKYEYE device!\n");
0109 rtems_fatal_error_occurred( status );
0110 }
0111 return RTEMS_SUCCESSFUL;
0112 }
0113
0114
0115 rtems_device_driver
0116 frame_buffer_open( rtems_device_major_number major,
0117 rtems_device_minor_number minor,
0118 void *arg)
0119 {
0120 if (pthread_mutex_trylock(&mutex)== 0){
0121
0122
0123
0124
0125 printk( "FBSKYEYE open called.\n" );
0126 enable_fbskyeye();
0127 return RTEMS_SUCCESSFUL;
0128 }
0129
0130 return RTEMS_UNSATISFIED;
0131 }
0132
0133
0134 rtems_device_driver
0135 frame_buffer_close(rtems_device_major_number major,
0136 rtems_device_minor_number minor,
0137 void *arg)
0138 {
0139 if (pthread_mutex_unlock(&mutex) == 0){
0140
0141
0142
0143 printk( "fbskyeye close called.\n" );
0144 disable_fbskyeye();
0145 return RTEMS_SUCCESSFUL;
0146 }
0147
0148 return RTEMS_UNSATISFIED;
0149 }
0150
0151 rtems_device_driver
0152 frame_buffer_read( rtems_device_major_number major,
0153 rtems_device_minor_number minor,
0154 void *arg)
0155 {
0156 rtems_libio_rw_args_t *rw_args = (rtems_libio_rw_args_t *)arg;
0157 rw_args->bytes_moved = ((rw_args->offset + rw_args->count) > fb_fix.smem_len ) ? (fb_fix.smem_len - rw_args->offset) : rw_args->count;
0158 memcpy(rw_args->buffer, (const void *) (fb_fix.smem_start + rw_args->offset), rw_args->bytes_moved);
0159 return RTEMS_SUCCESSFUL;
0160 }
0161
0162 rtems_device_driver
0163 frame_buffer_write( rtems_device_major_number major,
0164 rtems_device_minor_number minor,
0165 void * arg)
0166 {
0167 rtems_libio_rw_args_t *rw_args = (rtems_libio_rw_args_t *)arg;
0168 rw_args->bytes_moved = ((rw_args->offset + rw_args->count) > fb_fix.smem_len ) ? (fb_fix.smem_len - rw_args->offset) : rw_args->count;
0169 memcpy( (void *) (fb_fix.smem_start + rw_args->offset), rw_args->buffer, rw_args->bytes_moved);
0170 return RTEMS_SUCCESSFUL;
0171 }
0172
0173 static int get_palette( struct fb_cmap *cmap )
0174 {
0175 uint32_t i;
0176
0177 if ( cmap->start + cmap->len >= 16 )
0178 return 1;
0179
0180 for( i = 0; i < cmap->len; i++ ) {
0181 cmap->red[ cmap->start + i ] = red16[ cmap->start + i ];
0182 cmap->green[ cmap->start + i ] = green16[ cmap->start + i ];
0183 cmap->blue[ cmap->start + i ] = blue16[ cmap->start + i ];
0184 }
0185 return 0;
0186 }
0187
0188 static int set_palette( struct fb_cmap *cmap )
0189 {
0190 uint32_t i;
0191
0192 if ( cmap->start + cmap->len >= 16 )
0193 return 1;
0194
0195 for( i = 0; i < cmap->len; i++ ) {
0196 red16[ cmap->start + i ] = cmap->red[ cmap->start + i ];
0197 green16[ cmap->start + i ] = cmap->green[ cmap->start + i ];
0198 blue16[ cmap->start + i ] = cmap->blue[ cmap->start + i ];
0199 }
0200 return 0;
0201 }
0202
0203
0204 rtems_device_driver
0205 frame_buffer_control( rtems_device_major_number major,
0206 rtems_device_minor_number minor,
0207 void * arg
0208 )
0209 {
0210 rtems_libio_ioctl_args_t *args = arg;
0211 printk(
0212 "FBSKYEYE ioctl called, cmd=%" PRIdioctl_command_t "\n",
0213 args->command
0214 );
0215 switch( args->command )
0216 {
0217 case FBIOGET_FSCREENINFO:
0218 args->ioctl_return = get_fix_screen_info( ( struct fb_fix_screeninfo * ) args->buffer );
0219 break;
0220 case FBIOGET_VSCREENINFO:
0221 args->ioctl_return = get_var_screen_info( ( struct fb_var_screeninfo * ) args->buffer );
0222 break;
0223 case FBIOPUT_VSCREENINFO:
0224
0225 args->ioctl_return = -1;
0226 return RTEMS_UNSATISFIED;
0227 case FBIOGETCMAP:
0228 args->ioctl_return = get_palette( ( struct fb_cmap * ) args->buffer );
0229 break;
0230 case FBIOPUTCMAP:
0231 args->ioctl_return = set_palette( ( struct fb_cmap * ) args->buffer );
0232 break;
0233 default:
0234 args->ioctl_return = 0;
0235 break;
0236
0237 }
0238 return RTEMS_SUCCESSFUL;
0239 }