view miscutil/fc-rgbconv.c @ 497:74610c4f10f7

target-utils: added 10 ms delay at the end of abb_power_off() The deosmification of the ABB access code (replacement of osmo_delay_ms() bogus delays with correctly-timed ones, which are significantly shorter) had one annoying side effect: when executing the poweroff command from any of the programs, one last '=' prompt character was being sent (and received by the x86 host) as the Calypso board powers off. With delays being shorter now, the abb_power_off() function was returning and the standalone program's main loop was printing its prompt before the Iota chip fully executed the switch-off sequence! I thought about inserting an endless tight loop at the end of the abb_power_off() function, but the implemented solution of a 10 ms delay is a little nicer IMO because if the DEVOFF operation doesn't happen for some reason in a manual hacking scenario, there won't be an artificial blocker in the form of a tight loop keeping us from further poking around.
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 25 May 2019 20:44:05 +0000
parents e7502631a0f9
children
line wrap: on
line source

/*
 * This utility is an aid for phone UI development.  The color LCDs in the
 * phones targeted by FreeCalypso implement 16-bit color in RGB 5:6:5 format,
 * but these 16-bit color words are not particularly intuitive in raw hex form.
 * In contrast, a 24-bit RGB 8:8:8 color given in RRGGBB hex form is quite
 * intuitive, at least to those who understand RGB.
 *
 * This utility performs the conversion.  It takes a single command line
 * argument that must be either 4 or 6 hex digits.  If the argument is 4 hex
 * digits, it is interpreted as RGB 5:6:5 and converted into RGB 8:8:8.
 * If the argument is 6 hex digits, it is interpreted as RGB 8:8:8 and
 * converted into RGB 5:6:5.  The output of the conversion is emitted on
 * stdout as 4 or 6 hex digits.
 */

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

is_arg_all_hex(str)
	char *str;
{
	char *cp;
	int c;

	for (cp = str; c = *cp++; )
		if (!isxdigit(c))
			return(0);
	return(1);
}

convert_565_to_888(in)
	unsigned in;
{
	unsigned r, g, b;

	r = in >> 11;
	g = (in >> 5) & 0x3F;
	b = in & 0x1F;
	printf("%02X%02X%02X\n", r << 3, g << 2, b << 3);
}

convert_888_to_565(in)
	unsigned in;
{
	unsigned r, g, b;

	r = (in >> 16) >> 3;
	g = ((in >> 8) & 0xFF) >> 2;
	b = (in & 0xFF) >> 3;
	printf("%04X\n", (r << 11) | (g << 5) | b);
}

main(argc, argv)
	char **argv;
{
	unsigned in;

	if (argc != 2) {
usage:		fprintf(stderr,
		    "please specify one 4-digit or 6-digit hex RGB value\n");
		exit(1);
	}
	if (!is_arg_all_hex(argv[1]))
		goto usage;
	in = strtoul(argv[1], 0, 16);
	switch (strlen(argv[1])) {
	case 4:
		convert_565_to_888(in);
		exit(0);
	case 6:
		convert_888_to_565(in);
		exit(0);
	}
	goto usage;
}