drivers/auxdisplay/ht16k33.c

Source file repositories/reference/linux-study-clean/drivers/auxdisplay/ht16k33.c

File Facts

System
Linux kernel
Corpus path
drivers/auxdisplay/ht16k33.c
Extension
.c
Size
19233 bytes
Lines
785
Domain
Driver Families
Bucket
drivers/auxdisplay
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

struct ht16k33_keypad {
	struct i2c_client *client;
	struct input_dev *dev;
	uint32_t cols;
	uint32_t rows;
	uint32_t row_shift;
	uint32_t debounce_ms;
	uint16_t last_key_state[HT16K33_MATRIX_KEYPAD_MAX_COLS];

	wait_queue_head_t wait;
	bool stopped;
};

struct ht16k33_fbdev {
	struct fb_info *info;
	uint32_t refresh_rate;
	uint8_t *buffer;
	uint8_t *cache;
};

struct ht16k33_priv {
	struct i2c_client *client;
	struct delayed_work work;
	struct led_classdev led;
	struct ht16k33_keypad keypad;
	union {
		struct ht16k33_fbdev fbdev;
		struct linedisp linedisp;
	};
	enum display_type type;
	uint8_t blink;
};

#define ht16k33_work_to_priv(p)				\
	container_of(p, struct ht16k33_priv, work.work)

#define ht16k33_led_to_priv(p)				\
	container_of(p, struct ht16k33_priv, led)

#define ht16k33_linedisp_to_priv(p)			\
	container_of(p, struct ht16k33_priv, linedisp)

static const struct fb_fix_screeninfo ht16k33_fb_fix = {
	.id		= DRIVER_NAME,
	.type		= FB_TYPE_PACKED_PIXELS,
	.visual		= FB_VISUAL_MONO10,
	.xpanstep	= 0,
	.ypanstep	= 0,
	.ywrapstep	= 0,
	.line_length	= HT16K33_MATRIX_LED_MAX_ROWS,
	.accel		= FB_ACCEL_NONE,
};

static const struct fb_var_screeninfo ht16k33_fb_var = {
	.xres = HT16K33_MATRIX_LED_MAX_ROWS,
	.yres = HT16K33_MATRIX_LED_MAX_COLS,
	.xres_virtual = HT16K33_MATRIX_LED_MAX_ROWS,
	.yres_virtual = HT16K33_MATRIX_LED_MAX_COLS,
	.bits_per_pixel = 1,
	.red = { 0, 1, 0 },
	.green = { 0, 1, 0 },
	.blue = { 0, 1, 0 },
	.left_margin = 0,
	.right_margin = 0,
	.upper_margin = 0,
	.lower_margin = 0,
	.vmode = FB_VMODE_NONINTERLACED,
};

static int ht16k33_display_on(struct ht16k33_priv *priv)
{
	uint8_t data = REG_DISPLAY_SETUP | REG_DISPLAY_SETUP_ON | priv->blink;

	return i2c_smbus_write_byte(priv->client, data);
}

static int ht16k33_display_off(struct ht16k33_priv *priv)
{
	return i2c_smbus_write_byte(priv->client, REG_DISPLAY_SETUP);
}

static int ht16k33_brightness_set(struct ht16k33_priv *priv,
				  unsigned int brightness)
{
	int err;

	if (brightness == 0) {
		priv->blink = REG_DISPLAY_SETUP_BLINK_OFF;
		return ht16k33_display_off(priv);
	}

Annotation

Implementation Notes