From owner-freebsd-arch@FreeBSD.ORG Sun Apr 12 00:11:48 2015 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 28CDC981; Sun, 12 Apr 2015 00:11:48 +0000 (UTC) Received: from mail-ig0-x22c.google.com (mail-ig0-x22c.google.com [IPv6:2607:f8b0:4001:c05::22c]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 02F00B84; Sun, 12 Apr 2015 00:11:47 +0000 (UTC) Received: by igbpi8 with SMTP id pi8so6687907igb.0; Sat, 11 Apr 2015 17:11:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:date:message-id:subject:from:to:content-type; bh=d1M7k4evNMsU4TGB7b4mpCzbMhrfBUOlg/EjDzSwcmo=; b=V42Rtm4x28vesRUxdnlipkwt/gdGqBPDWwsfAhgRL685/ve9ZOZfnwqYUJWUNG9M4U wys6TDjrtTK87F/TgzNDW3ZBm0S1+E7sDbJYFFXkhM7DVqkEfYVGiL5eUBq5Svd5GpQO QY1wy9XWn1vsvQlivSxDXrF6SaqwunqPhwqi4M9FTH9UMfCC1rPSox/eAegHg09Oxy0i rB7kSFh4NcMfcoX2qJQXZV83bw0j/B0LoqWrTygxpHvBrvz0dU4m0vNoJihDkbcMs/H5 jKJqWQfjujnbV/DPo2xWX4VgRreQiHg+q9r/MDMKzwSa9evedvHg84hvxIgr4fb2ylTM d04g== MIME-Version: 1.0 X-Received: by 10.42.137.202 with SMTP id z10mr11525295ict.37.1428797507346; Sat, 11 Apr 2015 17:11:47 -0700 (PDT) Sender: adrian.chadd@gmail.com Received: by 10.36.17.194 with HTTP; Sat, 11 Apr 2015 17:11:47 -0700 (PDT) Date: Sat, 11 Apr 2015 17:11:47 -0700 X-Google-Sender-Auth: SxNU6A1b7DU9itycciBBxUrkVug Message-ID: Subject: using libgpio to bitbang LCDs! From: Adrian Chadd To: "freebsd-embedded@freebsd.org" , "freebsd-arch@freebsd.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 12 Apr 2015 00:11:48 -0000 Hi! I just ported an adafruit LCD driver to FreeBSD. This was a pretty trivial task: * convert C++ to C, which was done primarily to not rely on the arduino-isms; * use libgpio to bitbang the SPI bus needed to write to the LCD. It worked third time. First was "oh it runs on 5v power and 3.3v signaling", and I had it hooked up to 3.3. Second was "Oh, I haven't set the pins to be output pins yet." Third time worked - just slowly. However - using libgpio was just pleasant. Get a handle, set the pin config, set the pins high/low. It was pretty damned wonderful. It turns out that to fill the screen with individual pixel writes takes quite a few seconds pinning my AR9331 CPU doing ~ 190,000 syscalls a second. Ian's suggested something sensible - a bulk data ioctl() that can bit bang a series of GPIO pins in the kernel. Ie, one syscall, a big chunk of data with instructions and timings. The other interesting thing would be a kind of bulk pin set/get - ie, instead of doing rmw for one pin at a time, communicate down masks of pins to do together. There are some devices (eg these LCDs) that allow you to treat it as a 6800/8080 MCU and do 8 bit data reads/writes, so being able to do that via the GPIO interface would be nice. The arduino API doesn't do this, so people (and I'm not making this up) will bitshift a byte into different GPIO pin set/get, rather than use an 8 bit port as an 8 bit port. I'll put the code up soon in case anyone wants to start poking these embedded LCDs from FreeBSD. * = Carambola 2 (AR9331) with GPIO pins attached, to an Adafruit SSD1331 96x64 OLED display.