Added support for brightness

This commit is contained in:
daniilfigasystems authored and Martijn de Vos committed 2024-12-22 11:41:17 +01:00
1 parent 0d8014f8db
commit 0cb390e281
6 files changed
+68 -19

No files matched your search

+11 -8
View File
@@ -34,8 +34,8 @@ static void read_nand_pages(IPodTouchFMSSState *s)
cpu_physical_memory_write(0x0ff2206c, chr, strlen(chr));
int page_out_buf_ind = 0;
dump_registers(s);
printf("Start CMD...\n");
//dump_registers(s);
//printf("Start CMD...\n");
for(int page_ind = 0; page_ind < s->reg_num_pages; page_ind++) {
uint32_t page_nr = 0;
uint32_t page_out_addr = 0;
@@ -47,7 +47,7 @@ static void read_nand_pages(IPodTouchFMSSState *s)
if(cs > 3) {
printf("CS %d invalid! (original CS: %d, reading page %d)\n", cs, og_cs, page_nr);
dump_registers(s);
//dump_registers(s);
hw_error("CS %d invalid!", cs);
}
@@ -76,7 +76,7 @@ static void read_nand_pages(IPodTouchFMSSState *s)
for(int i = 0; i < 2; i++) {
cpu_physical_memory_read(s->reg_pages_out_addr + (page_out_buf_ind * sizeof(uint32_t)), &page_out_addr, sizeof(uint32_t));
cpu_physical_memory_write(page_out_addr, s->page_buffer + i * write_buf_size, write_buf_size);
printf("Will read page %d @ cs %d into address 0x%08x and spare into address 0x%08x\n", page_nr, cs, page_out_addr, s->reg_page_spare_out_addr);
//printf("Will read page %d @ cs %d into address 0x%08x and spare into address 0x%08x\n", page_nr, cs, page_out_addr, s->reg_page_spare_out_addr);
page_out_buf_ind++;
}
@@ -88,7 +88,7 @@ static void read_nand_pages(IPodTouchFMSSState *s)
static uint64_t ipod_touch_fmss_read(void *opaque, hwaddr addr, unsigned size)
{
//fprintf(stderr, "%s: read from location 0x%08x\n", __func__, addr);
//fprintf(stderr, "%s: read from location 0x%08lx\n", __func__, addr);
IPodTouchFMSSState *s = (IPodTouchFMSSState *)opaque;
switch(addr)
@@ -115,7 +115,7 @@ static uint64_t ipod_touch_fmss_read(void *opaque, hwaddr addr, unsigned size)
static void ipod_touch_fmss_write(void *opaque, hwaddr addr, uint64_t val, unsigned size)
{
IPodTouchFMSSState *s = (IPodTouchFMSSState *)opaque;
//printf("%s: writing 0x%08x to 0x%08x\n", __func__, val, addr);
//printf("%s: writing 0x%08lx to 0x%08lx\n", __func__, val, addr);
switch(addr) {
case 0xC00:
@@ -150,8 +150,11 @@ static void ipod_touch_fmss_write(void *opaque, hwaddr addr, uint64_t val, unsig
break;
case 0xD38:
if(s->reg_csgenrc == 0xa01) { read_nand_pages(s); }
else { printf("NAND write %ld addr %ld\n", val, addr); temp_storage[addr] = val;/*cpu_physical_memory_write(addr, val, sizeof(val)); */}
else { /*printf("NAND write %ld addr %ld\n", val, addr); temp_storage[addr] = val;*//*cpu_physical_memory_write(addr, val, sizeof(val)); */}
break;
default:
//printf("%s unknown write %lx to %lx\n", __func__, val, addr);
break;
}
}
+11 -3
View File
@@ -3,6 +3,8 @@
#include "ui/console.h"
#include "hw/display/framebuffer.h"
int lcd_brightness = 255;
static uint64_t ipod_touch_lcd_read(void *opaque, hwaddr addr, unsigned size)
{
// printf("%s: read from location 0x%08x\n", __func__, addr);
@@ -64,6 +66,11 @@ static void ipod_touch_lcd_write(void *opaque, hwaddr addr, uint64_t val, unsign
}
}
void lcd_changebrightness(int brightness)
{
lcd_brightness = brightness & 0xFF;
}
static void lcd_invalidate(void *opaque)
{
IPodTouchLCDState *s = opaque;
@@ -72,6 +79,7 @@ static void lcd_invalidate(void *opaque)
static void draw_line32_32(void *opaque, uint8_t *d, const uint8_t *s, int width, int deststep)
{
// IPodTouchLCDState *lcd = (IPodTouchLCDState *) opaque;
uint8_t r, g, b;
do {
@@ -80,8 +88,8 @@ static void draw_line32_32(void *opaque, uint8_t *d, const uint8_t *s, int width
b = s[0];
g = s[1];
r = s[2];
//printf("R: %d, G: %d, B: %d\n", r, g, b);
((uint32_t *) d)[0] = rgb_to_pixel32(r, g, b);
// printf("R: %d, G: %d, B: %d, A: %d\n", r, g, b, lcd_brightness);
((uint32_t *) d)[0] = rgb_to_pixel32(round((float)r * ((float)lcd_brightness / 255.0f)), round((float)g * ((float)lcd_brightness / 255.0f)), round((float)b * ((float)lcd_brightness / 255.0f)));
s += 4;
d += 4;
} while (-- width != 0);
@@ -173,7 +181,7 @@ static void refresh_timer_tick(void *opaque)
else if (s->render == 0xFF)
qemu_irq_lower(s->irq);
timer_mod(s->refresh_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + NANOSECONDS_PER_SECOND / 85);//LCD_REFRESH_RATE_FREQUENCY);
timer_mod(s->refresh_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + NANOSECONDS_PER_SECOND / 60);//LCD_REFRESH_RATE_FREQUENCY);
}
static void ipod_touch_lcd_realize(DeviceState *dev, Error **errp)
+30 -1
View File
@@ -1,7 +1,21 @@
#include "hw/arm/ipod_touch_pcf50633_pmu.h"
#include "hw/arm/ipod_touch_lcd.h"
static int pcf50633_event(I2CSlave *i2c, enum i2c_event event)
{
Pcf50633State *s = PCF50633(i2c);
// printf("%s Event %d\n", __func__, s->cmd);
if (event == I2C_START_SEND)
{
// printf("%s start send %d\n", __func__, s->cmd);
}
else if (event == I2C_FINISH)
{
s->ready = 1;
// printf("%s end send %d\n", __func__, s->cmd);
}
return 0;
}
@@ -70,7 +84,22 @@ static uint8_t pcf50633_recv(I2CSlave *i2c)
static int pcf50633_send(I2CSlave *i2c, uint8_t data)
{
Pcf50633State *s = PCF50633(i2c);
s->cmd = data;
if (s->ready)
{
s->curreg = data;
s->ready = 0;
}
else
{
s->cmd = data;
}
printf("Writing PMU register cmd %d reg %d\n", s->cmd, s->curreg);
switch(s->curreg) {
case PMU_DSBL1:
lcd_changebrightness(s->cmd);
break;
}
return 0;
}
+9 -6
View File
@@ -19,7 +19,7 @@ void sdio_exec_cmd(IPodTouchSDIOState *s)
else if(cmd_type == 0x5) {
if(addr == 0) {
// reading slot 0 - make sure there is a device here
s->resp0 = (1 << 31) /* indicate ready */ | (BCM4325_FUNCTIONS << CMD5_FUNC_OFFSET) /* number of functions */;
//s->resp0 = (1 << 31) /* indicate ready */ | (BCM4325_FUNCTIONS << CMD5_FUNC_OFFSET) /* number of functions */;
}
}
else if(cmd_type == 0x7) {
@@ -52,7 +52,7 @@ void sdio_exec_cmd(IPodTouchSDIOState *s)
// CMD53 - block transfer
addr = addr & 0x7fff;
bool is_write = (s->arg >> 31) != 0;
printf("SDIO: Executing cmd53 with block size %d and %d blocks (reg address: 0x%08x, destination address: 0x%08x, write? %d)\n", s->blklen, s->numblk, addr, s->baddr, is_write);
printf("SDIO: Executing cmd53 func %x with block size %d and %d blocks (reg address: 0x%08x, destination address: 0x%08x, write? %d)\n", func, s->blklen, s->numblk, addr, s->baddr, is_write);
if(is_write) {
if(func == 0x1) {
@@ -61,7 +61,7 @@ void sdio_exec_cmd(IPodTouchSDIOState *s)
else if(func == 0x2) {
// this is a BCM4325 command - add a frame to the queue and schedule the IRQ request to indicate that the command has been completed
BCM4325FrameHeaderPacket *frame_header = calloc(sizeof(BCM4325FrameHeaderPacket), sizeof(uint8_t *));
uint16_t length = 14;
uint16_t length = s->blklen * s->numblk;
frame_header->frame_length = length;
frame_header->checksum = length ^ 0xffff;
g_queue_push_tail(s->rx_fifo, frame_header);
@@ -83,6 +83,9 @@ void sdio_exec_cmd(IPodTouchSDIOState *s)
if(!frame_header) {
// create an empty frame
frame_header = calloc(sizeof(BCM4325FrameHeaderPacket), sizeof(uint8_t *));
frame_header->frame_length = s->blklen * s->numblk;
frame_header->checksum = (s->blklen * s->numblk) ^ 0xffff;
}
cpu_physical_memory_write(s->baddr, frame_header, sizeof(BCM4325FrameHeaderPacket));
}
@@ -164,11 +167,11 @@ static uint64_t ipod_touch_sdio_read(void *opaque, hwaddr addr, unsigned size)
case SDIO_RESP0:
return s->resp0;
case SDIO_RESP1:
return s->resp1;
return s->resp1 == 0 ? 0x7465 : s->resp1;
case SDIO_RESP2:
return s->resp2;
return s->resp2 == 0 ? 0x7374 : s->resp2;
case SDIO_RESP3:
return s->resp3;
return s->resp3 == 0 ? 0xFFFF : s->resp3;
case SDIO_CSR:
return s->csr;
case SDIO_IRQ:
+3
View File
@@ -22,6 +22,7 @@ typedef struct IPodTouchLCDState
QemuConsole *con;
IPodTouchMultitouchState *mt;
int invalidate;
uint8_t brightness;
MemoryRegionSection fbsection;
qemu_irq irq;
uint32_t lcd_con;
@@ -36,4 +37,6 @@ typedef struct IPodTouchLCDState
QEMUTimer *refresh_timer;
} IPodTouchLCDState;
void lcd_changebrightness(int brightness);
#endif
+4 -1
View File
@@ -12,6 +12,7 @@
#define TYPE_PCF50633 "pcf50633"
OBJECT_DECLARE_SIMPLE_TYPE(Pcf50633State, PCF50633)
#define PMU_DSBL1 0x30
#define PMU_MBCS1 0x4B
#define PMU_ADCC1 0x57
@@ -27,6 +28,8 @@ OBJECT_DECLARE_SIMPLE_TYPE(Pcf50633State, PCF50633)
typedef struct Pcf50633State {
I2CSlave i2c;
uint32_t cmd;
uint32_t ready;
uint32_t curreg;
} Pcf50633State;
#endif
#endif