From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.58.94.166 with SMTP id dd6mr7828728veb.12.1403471106793; Sun, 22 Jun 2014 14:05:06 -0700 (PDT) Path: border1.nntp.dca1.giganews.com!buffer1.nntp.dca1.giganews.com!border1.nntp.dca3.giganews.com!backlog3.nntp.dca3.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!i13no9508202qae.1!news-out.google.com!q9ni21018qaj.0!nntp.google.com!peer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post02.iad.highwinds-media.com!fx07.iad.POSTED!not-for-mail From: Shark8 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:32.0) Gecko/20100101 Thunderbird/32.0a1 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Cleanest Ada way to do this? References: <7eaee5fc-2045-4bb3-8b16-d757b54760da@googlegroups.com> In-Reply-To: <7eaee5fc-2045-4bb3-8b16-d757b54760da@googlegroups.com> Message-ID: <6yHpv.55741$G37.7010@fx07.iad> X-Complaints-To: abuse@teranews.com NNTP-Posting-Date: Sun, 22 Jun 2014 21:05:06 UTC Organization: TeraNews.com Date: Sun, 22 Jun 2014 15:05:05 -0600 X-Received-Bytes: 2634 X-Received-Body-CRC: 152239308 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Original-Bytes: 3096 Xref: number.nntp.dca.giganews.com comp.lang.ada:187174 Date: 2014-06-22T15:05:05-06:00 List-Id: On 22-Jun-14 10:51, Mike Silva wrote: > I'd like some help on the cleanest, or most elegant, way to do this in Ada. > I'm writing to an LCD character display, in 4-bit mode, which requires writing > an 8 bit character or command value as two 4 bit pieces. The port (a memory > address) being written to is 32 bits wide. What I would like to be able to do > is some form of this (not valid Ada, I know): > > Port32(4..7) := Some_Char(4..7); > ..twiddle some other control bits.. > Port32(4..7) := Some_Char(0..3); > ..twiddle some other control bits.. > > Any thoughts? > Depends on the situation, I think; if there's a lot of them [ports] like say one for each 'character' you may be better off making a generic package to interface with it. Package Parent is Type Segment is range 1..16 with Size => 4; Type LCD_Character is private; Type LCD_Handle is not null access LCD_Character; Private Type Segment_Array is Array(Segment) of Boolean with Size => Segment'Last; Type LCD_Character is record Segments : Segment_Array; end record; End Parent; Generic Port_Address : in Address; Package Parent.Port is Port : aliased LCD_Character with Volatile, Address => Port_Address; End Parent.port; With Parent.Port; Package Display is Number_of_Segments : Constant Positive := 3; Type LCD_Array is Array(1..Number_of_Segments) of LCD_Handle; Display : constant LCD_Array; Private Package Segment_1 is new Parent.Port( ######## ); Package Segment_2 is new Parent.Port( ######## ); Package Segment_3 is new Parent.Port( ######## ); Display : constant LCD_Array:= ( 1 => Segment_1.Port, 2 => Segment_2.Port, 3 => Segment_3.Port ); End Display; Or if it's a one-off type thing do it more directly: LCD_Display : LCD_Character with Address => Port_Address;