ov3660: add a driver for the OV3660 camera (ESP32 camera boards)

Aperta
#901 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
22/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
go
Ambito
embedded-iot

Direzione di ricerca

This is a proposal, not a ready task: the author asks three design questions (one package per chip or a shared camera package, JPEG-only first version, and deferring the capture example). Read the proposed Config/Device API and the register-table generator idea, then wait for a maintainer decision on those questions before starting. Done means an agreed API and an approved first pull request.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

The short version

I want to add a driver for the OV3660 camera. It is the camera on many cheap ESP32 camera boards, for example the Freenove ESP32-WROVER CAM. Your CONTRIBUTING.md asks for an issue first, so here it is, with the API, the status and some questions.

The ESP32 side (the camera input that catches the picture bytes) is a separate proposal in TinyGo: https://github.com/tinygo-org/tinygo/issues/5820

Fun fact first

The Freenove book says the board has an OV2640. Mine has an OV3660. The chip ID register says 0x3660. So check yours before you trust the box!

What the driver does

It sets up the camera over I2C (the camera calls it SCCB):

  • finds the chip (product ID 0x3660)
  • resets it and loads the setup tables
  • sets the picture size, from 160 x 120 up to 2048 x 1536
  • JPEG output, with a quality setting
  • flip, mirror, and the colour bar test pattern

It does not read the pictures. That is the job of the camera input in TinyGo (see the link above).

The proposed API

It follows the driver design guide: a Config, a Device, New with a drivers.I2C, and no allocations.

package ov3660

const Address = 0x3C

type Size uint8 // QQVGA (160 x 120), QVGA, CIF, VGA, SVGA, XGA, UXGA, QXGA (2048 x 1536)
type Format uint8 // JPEG

type Config struct {
	Size    Size
	Format  Format
	Quality uint8  // JPEG quality, 0 to 63, lower is better
	XCLK    uint32 // the camera input clock in Hz
}

func DefaultConfig(xclk uint32) Config // 320 x 240, JPEG, quality 12
func (c Config) Validate() error

func New(bus drivers.I2C) Device
func (d *Device) Connected() bool
func (d *Device) Configure(cfg Config) error
func (d *Device) SetSize(s Size) error
func (d *Device) SetQuality(q uint8) error
func (d *Device) SetFlip(vertical, horizontal bool) error
func (d *Device) SetColorBar(on bool) error

Two details I am happy about

  • The register tables are generated, not typed by hand. A small generator (go generate) reads Espressif's esp32-camera header and writes tables.go. So we can compare with the source, and nobody has to check 200 lines of hex by eye.
  • The clock settings stay inside the datasheet limits. Espressif's values for the internal PLL are outside the range that the OV3660 datasheet allows, at the 10 MHz input clock the ESP32 can make. The driver computes values inside the range. On my board it gives about 27 pictures per second, against 14 with the Espressif values.

Status

  • Driver plus 8 unit tests with a fake I2C bus: all pass.
  • Tested on the Freenove ESP32-WROVER CAM: real JPEG pictures at 160 x 120, 320 x 240 and 640 x 480, plus 10 minutes non-stop without an error.
  • An example that finds and sets up the camera. It builds with TinyGo 0.42.

One honest known problem

In about 2 of 80 test runs, real pictures came out green. The JPEG is complete and valid, but its colour planes copy the brightness plane. The colour bar test pattern was always perfect. I could not trigger it again on purpose, so I did not "fix" it with a guess. If you have seen this with an OV3660 before, I would love a hint!

Questions for you

  1. One package per chip (ov3660, and later ov2640), or first a small shared camera package that detects which chip is there?
  2. JPEG only for a first version. OK?
  3. The capture example. An example that also takes pictures needs the new TinyGo camera input. The CI uses released TinyGo, so I would add that example in a later pull request, after a TinyGo release. OK?

Thanks for reading!

Lingua principale
Go
Stelle
756
Fork
251
Merge medio
7g 12h
PR unite (30g)
8

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di tinygo-org/drivers

Tutte le issue di tinygo-org/drivers

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.